经典ASP中的Jquery AJAX POST请求问题

时间:2014-07-14 07:47:31

标签: jquery ajax asp-classic

我正在使用jQuery AJAX,以下是我的代码:

$.ajax({
    type: "POST",         
    contentType: "multipart/form-data; charset=UTF-8",
    url: "../common/targetpage.asp",
    data: 'items=' + encodeURIComponent("123"),
    cache: false,        
    success: function (data) {
        if ($(data).find('couponDiscount').length > 0) {
            var couponDiscount = $(data).find('couponDiscount').text();
            return couponDiscount;
        }
        else {
            if ($(data).find('couponError').length > 0) {
                var couponError = $(data).find('couponError').text();
                alert(couponError);
                return 0;
            }
        }
    },
    error: function (result) {
        alert(result.responseText);
    }
});

当我在target.asp页面上使用以下行时,它什么都没有:

Response.Write(Trim(Request.Form("items")))
Response.End

但是当我查看IE Developer工具时:我请求Body Section我找到了“items = 123”(没有双引号)。我无法弄清楚这个问题。

1 个答案:

答案 0 :(得分:1)

我认为您错误地使用了 AJAX 调用中的数据。通常用作:

$.ajax({
    type: "POST",         
    contentType: "multipart/form-data; charset=UTF-8",
    url: "../common/targetpage.asp",
    data: {items : encodeURIComponent("123")},
    cache: false,        

您正在向POST呼叫发送字符串而不是param。

来自jQuery documentation

  

data选项可以包含表单的查询字符串   key1 = value1& key2 = value2,或{key1:'value1'形式的对象,   key2:'value2'}。

希望这有助于你的事业。

相关问题