Reputation: 189
I wanna kn is it possible to pass query string along with URL when we call on Jquery Ajax;
Example :
$.ajax({
type: "POST",
url: "index.php?task=addNewInfo",
data: $('#regForm').serialize(),
dataType: "json",
.....
});
So does the query string from the param task works fine? or we need to do it the other way? Thank you.
Upvotes: 4
Views: 36115
Reputation:
Yes. query-string and request body are 2 different things in HTTP requests. jQuery wrap the data in the query-string for GET requests, which is probably the source of confusion
Upvotes: 0
Reputation: 388316
I think the following will work fine
url : "index.php?task=addNewInfo&" + $('#regForm').serialize()
But why do you want to pass the form values as query params? The post request will pass the values as request params anyway. These params will be sent via the request body which is why you are using POST
request type.
Upvotes: 4
Reputation: 6032
Send the task in the data parameter
data:"task=addNewInfo&" + $('#regForm').serialize()
This is for using POST method. If you want to use GET method then Arun's solution will work fine.
Upvotes: 9