Aana Saeed Aana Saeed - 4 months ago 21
jQuery Question

Passing multiple parameters with $.ajax url

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'];


?>

Answer

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,