jQuery 使用 $.ajax url 传递多个参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13651656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:50:21  来源:igfitidea点击:

Passing multiple parameters with $.ajax url

jqueryajax

提问by Aana Saeed

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

我在使用 ajax url 传递参数时遇到问题。我认为错误出在参数代码语法中。请帮忙。

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


 ?>

回答by Christian

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

为什么要结合 GET 和 POST?使用其中之一。

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

php:

php:

$uid =$_POST['uid'];

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

或者,只需正确格式化您的请求(您缺少 get 参数的&符号)。

url:"getdata.php?timestamp="+timestamp+"&uid="+id+"&uname="+name,

回答by ?????

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


    };
}?);?