Jump to content

jQuery Ajax make "normal" post request

Here is my code

$.ajax({
  url: url + comment_id,
  type: 'PUT',
  data: {
    comment: html
  }
});

What I want is when this is trigger it should do a normal request, etc I want my browser to redirect with the request as if it was a normal form submit. I have tried to google but all I find is how to make it not follow redirects, which is not what I'm looking for.

 

It does not need to be ajax, but I don't have a normal form, I need to create the request. So it could be a ajax, javascript or jquery, but not a new library.

Currently all the ajax calls have this in common which is a must to implement if it's not a ajax call.

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

 

Back-end developer, electronics "hacker"

Link to comment
https://linustechtips.com/topic/992263-jquery-ajax-make-normal-post-request/
Share on other sites

Link to post
Share on other sites

If you want to redirect you should do it differently, you are now just making a request in the background.
You can redirect with window.location.replace() and use params in the url to include the form data.

You could also just use html forms with the action attribute

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×