Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding query string to Ajax url call

Tags:

jquery

ajax

url

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.

like image 329
H.dev.guy Avatar asked Dec 13 '22 02:12

H.dev.guy


2 Answers

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.

like image 83
Imdad Avatar answered Dec 14 '22 16:12

Imdad


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.

like image 20
Arun P Johny Avatar answered Dec 14 '22 14:12

Arun P Johny