English 中文(简体)
我想发送两个参数 在一个 ajax 请求
原标题:I want to send two parameters on one ajax request
  • 时间:2012-05-25 13:15:46
  •  标签:
  • jquery
  • ajax

I have this code"

I want send two valit=$( {p> $(.ledit) ) 发送领导2 数据时,我要发送两个值,因为我看到我在数据中已经发送领导2, 想要发送领导2 成功 : 函数 (dddddddd) {}} }} } {(ddddddddddd); html (ddddddddddd); } } } ;

;
问题回答

您可以设置 data 属性为对象 :

$( .ledit ).click(function() {
    var ledit = $(this).attr("id");
    var ledit2 = $( .valu ).val();

    $.ajax({
        url:  edit.php ,
        data: {
            ledit : ledit,
            ledit2 : ledit2
        },
        success: function(data) {
            $( .edito ).html( dddddddddd );
        }
    });
});​

您可以对 data 参数使用对象字典:

data: { ledit: ledit, ledit2: ledit2 }

也可以在 URL 中使用 运算符 :

data:  ledit=  + ledit +  &ledit2=  + ledit2

为什么打两个电话?只要打一个AJAX电话,传递两个价值观

$.ajax({
        url:  edit.php ,
        data:  ledit=  + ledit + "&ledit2=" + ledit2,
        ...
});

除非您按照@VisioN 的建议编码您的值(例如 encodeURIComponent ),否则最好使用一个对象。

你试过这样吗?

    $.ajax({
        url:  edit.php ,
        data:  { "ledit":  + ledit +  , "ledit2":  + ledit2 +  } ,
        success: function(data) {
            $( .edito ).html( dddddddddd );
        }
    });

或更好些:

    $.ajax({
        url:  edit.php ,
        data: JSON.stringify({ ledit: ledit, ledit2: ledit2}),
        success: function(data) {
            $( .edito ).html( dddddddddd );
        }
    });


上一篇:
下一篇:


相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签