jQuery AJAX和VBscript – 在jQuery AJAX中使用POST时无法获取VBscript变量中的值

我在.asp页面上获取VBscript时遇到问题,无法为jQuery ajax()函数发送的变量赋值。

我在其他几个网站上有这个代码,它工作正常,但由于某种原因,它不适用于这个网站。

为了防止它产生影响,我们通过IIS7运行这些网站。

问题是VBscript页面上的变量没有被赋予javascript页面中传递的任何值。 但是,如果我将POST更改为GET并将request.form更改为request.queryString,它确实有效。 GET的问题是我们无法在没有414错误的情况下将非常多的数据输入到表单的Description字段中 – 因此使用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); } }); 

VBscript的:

 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 

任何帮助表示赞赏。

问题是你的变量不匹配,例如你正在strProdID 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")