0

我正在尝试将 2 个表单元素中的值添加到一个函数中,并且可以获得第一个添加但无法为第二个编写代码的正确方法。

$(function() {
   $('#form_orderTracking').click(function(){
       $('#CustomerDetails').load('TrackOrder1.asp?OrderID=' + $('#orderID').val());
   });
});

我正在尝试添加 emailAddress 字段的值,以便 url 读取:

TrackOrder1?OrderID=123456&EmailAddress=abc@123.com
4

2 回答 2

3

Instead of appending the query string to the url, you can pass it to .load as a 2nd parameter. If you pass an object, it'll use POST, if you pass a string, it'll use GET (like your example).

$.param converts the object to a string, so it uses GET.

$('#CustomerDetails').load('TrackOrder1.asp', $.param({
    orderID: $('#orderID').val(),
    EmailAddress: emailAddress
}));

Or you can just append to your string, like so:

$('#CustomerDetails').load('TrackOrder1.asp?OrderID=' + $('#orderID').val() + '&EmailAddress=' + emailAddress);
于 2012-04-27T20:15:08.147 回答
0
var url = 'TrackOrder1.asp?OrderID=' + uriEncodeComponent($('#orderID').val()) + '&EmailAddress=' + uriEncodeComponent(email);
$('#CustomerDetails').load(url);

It is also best to run the values through uriEncodeComponent() to ensure they are encoded properly.

于 2012-04-27T20:15:19.500 回答