jQuery AJAX和VBscript - 在jQuery AJAX中使用POST时,无法在VBscript变量中获取值 [英] jQuery AJAX and VBscript - Can't get values in VBscript variables when using POST in the jQuery AJAX

查看:139
本文介绍了jQuery AJAX和VBscript - 在jQuery AJAX中使用POST时,无法在VBscript变量中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在.asp页面上获取VBscript以将值分配给由jQuery ajax()函数发送的变量。



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



以防万一它有所作为,我们通过运行网站IIS7。



问题在于VBscript页面上的变量没有被分配任何在javascript页面中传递的值。
但是,如果我将POST更改为GET并将request.form更改为request.queryString,它确实有效。
GET的问题在于,我们无法输入非常多的数据到表单的描述字段中,而没有得到414错误 - 因此使用POST。



<正如我所说,我在其他几个网站上都有这个代码,所以我不知道为什么它不在这里工作。



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

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(更新成功)
},
错误:function(xhr){
alert(Ajax请求发生错误,错误状态为:+ 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& '
$ b $ dim rs:set rs = Server.CreateObject(ADODB.recordset)
rs.Open strSQL,cn,3,3

问题在于你的变量不匹配,例如你正在为 strProdID prodid 但看 c $ c>,在将数据作为对象传递之前不需要进行编码,让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()
},
成功:function(){
alert(更新成功)
},
error:function(xhr){
alert(Ajax请求发生错误,错误状态为:+ xhr.status);
}
});

另外在VBScript方面你有:

< pre $ strName = request.form(strSubCatID)

看起来应该是这样的:

$ $ $ $ $ c $ strName = request.form(strName)


I am having trouble getting the VBscript on a .asp page to assign values to variables which are sent by the jQuery ajax() function.

I have this code on several other sites and it works fine, but for some reason it won't work on this website.

Just in case it makes a difference we are running the sites through IIS7.

The issue is that the variables on the VBscript page don't get assigned any of the values passed in the javascript page. However if I change the POST to GET and change request.form to request.queryString it does work. The problem with GET is that we can't enter very much data into the Description field of our form without getting a 414 error - Hence the use of POST.

As I said, I have this code on several other sites so I can't figure out why it isn't working here.

Here is my code (It is a mix of older code and newer code):

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

Any help is appreciated.

解决方案

The problem is your variables aren't matching, for example you're POSTing prodid but looking for strProdID, also there's no need to encode before passing your data as an object, let jQuery do the encoding internally, for example:

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);
  }
});

Also on the VBScript side you have:

strName = request.form("strSubCatID")

Which looks like it should be:

strName = request.form("strName")

这篇关于jQuery AJAX和VBscript - 在jQuery AJAX中使用POST时,无法在VBscript变量中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆