【问题标题】:jQuery AJAX and VBscript - Can't get values in VBscript variables when using POST in the jQuery AJAXjQuery AJAX 和 VBscript - 在 jQuery AJAX 中使用 POST 时无法获取 VBscript 变量中的值
【发布时间】:2010-10-05 15:37:20
【问题描述】:

我无法让 .asp 页面上的 VBscript 为 jQuery ajax() 函数发送的变量赋值。

我在其他几个网站上都有这段代码,它运行良好,但由于某种原因,它无法在这个网站上运行。

以防万一我们通过 IIS7 运行网站。

问题是 VBscript 页面上的变量没有被分配任何在 javascript 页面中传递的值。 但是,如果我将 POST 更改为 GET 并将 request.form 更改为 request.queryString 它确实有效。 GET 的问题是我们不能在表单的 Description 字段中输入大量数据而不会出现 414 错误 - 因此使用 POST。

正如我所说,我在其他几个网站上都有此代码,所以我无法弄清楚为什么它在这里不起作用。

这是我的代码(它是旧代码和新代码的混合):

javascript:

var prodID = document.forms['hidden'].prodid.value;
var strSubCatID = document.forms['frmProducts'].cmbSubCategory.value;
var strName = encodeURIComponent(document.forms['frmProducts'].txtName.value);
var strDescription = encodeURIComponent(document.forms['frmProducts'].txtDesc.value);

jQuery.ajax({
    type: "POST",
    url: "/_ajax/products/updateDescription.asp",
    data: {
        "prodid": prodID,
        "strName": strName,
        "strSubCatID": strSubCatID,
        "strDescription": strDescription
    },
    success: function () {
        alert("Update successful")
    },
    error: function (xhr) {
        alert("Error occured during Ajax request, the error status is: " + xhr.status);
    }
});    

VB脚本:

dim strSubCatID : strSubCatID = request.form("strSubCatID")
dim strName : strName = request.form("strSubCatID")
dim strDescription : strDescription = request.form("strDescription")
dim strProdID : strProdID = request.form("strProdID")

strSQL = "UPDATE tblProducts SET "
strSQL = strSQL & "SubCatID = '" & strSubCatID & "', "
strSQL = strSQL & "Name = '" & strName & "', "
strSQL = strSQL & "Description = '" & strDescription & "' "
strSQL = strSQL & " WHERE ProdID = '" & strProdID & "'"

dim rs : set rs=Server.CreateObject("ADODB.recordset")
rs.Open strSQL, cn, 3, 3

感谢任何帮助。

【问题讨论】:

    标签: jquery ajax post vbscript get


    【解决方案1】:

    问题是您的变量不匹配,例如您正在发布 prodid 但正在寻找 strProdID,在将您的数据作为对象传递之前也无需编码,让jQuery在内部进行编码,例如:

    jQuery.ajax({
      type: "POST",
      url: "/_ajax/products/updateDescription.asp",
      data: {
        strProdID:      $("form[name=hidden] [name=prodid]").val(),
        strName:        $("form[name=frmProducts] [name=txtName]").val(),
        strSubCatID:    $("form[name=frmProducts] [name=cmbSubCategory]").val(),
        strDescription: $("form[name=frmProducts] [name=txtDesc]").val()
      },
      success: function() {
        alert("Update successful")
      },
      error: function(xhr){
        alert("Error occured during Ajax request, the error status is: " + xhr.status);
      }
    });
    

    在 VBScript 方面你也有:

    strName = request.form("strSubCatID")
    

    看起来应该是这样的:

    strName = request.form("strName")
    

    【讨论】:

      猜你喜欢
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多