Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple parameters with $.ajax url

Tags:

jquery

ajax

I am facing problem in passing parrameters with ajax url.I think error is in parametters code syntax.Plz help.

    var timestamp = null;
function waitformsg(id,name) {

    $.ajax({
        type:"Post",
        url:"getdata.php?timestamp="+timestamp+"uid="+id+"uname="+name,
       async:true,
       cache:false,
       success:function(data) {


        });
     }

I am accessing these parameters as follows

<?php          

  $uid =$_GET['uid'];


 ?>
like image 427
Aana Saeed Avatar asked Nov 30 '12 19:11

Aana Saeed


People also ask

How pass multiple parameters in URL jQuery Ajax in PHP?

function getInfo(val1, val2) { $. ajax({ type: "POST", url: "get_info. php", data: 'value1='+val1+'&value2'+val2, success: function(data){ $("#info"). html(data); } }); };


2 Answers

Why are you combining GET and POST? Use one or the other.

$.ajax({
    type: 'post',
    data: {
        timestamp: timestamp,
        uid: uid
        ...
    }
});

php:

$uid =$_POST['uid'];

Or, just format your request properly (you're missing the ampersands for the get parameters).

url:"getdata.php?timestamp="+timestamp+"&uid="+id+"&uname="+name,
like image 143
Christian Avatar answered Oct 19 '22 20:10

Christian


why not just pass an data an object with your key/value pairs then you don't have to worry about encoding

$.ajax({
    type: "Post",
    url: "getdata.php",
    data:{
       timestamp: timestamp,
       uid: id,
       uname: name
    },
    async: true,
    cache: false,
    success: function(data) {


    };
}​);​
like image 37
wirey00 Avatar answered Oct 19 '22 20:10

wirey00