Aana Saeed
Aana Saeed

Reputation: 299

Passing multiple parameters with $.ajax url

I am facing a problem in passing parameters with ajax URL. I think the error is in parameters code syntax. Please 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'];
?>

Upvotes: 17

Views: 159899

Answers (2)

wirey00
wirey00

Reputation: 33661

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) {


    };
}​);​

Upvotes: 5

Christian
Christian

Reputation: 19750

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,

Upvotes: 35

Related Questions