jQuery Ajax+经典ASP返回错误'意外的输入结束'

jQuery Ajax + Classic ASP return error 'unexpected end of input'

本文关键字:意外 输入 结束 Ajax+ 经典 返回 错误 jQuery ASP      更新时间:2023-09-26

我在这个组合上有两个问题。

  1. 在Ajax总是返回错误(意外的输入结束)之后,在localhost中它仍然可以成功保存日期,似乎不是什么大问题。

  2. 该代码在我的localhost中工作,但在1App Server中不工作(http://www.1apps.net/),我试着提交了一个技术问题,他们很快就用这种方式做出了回应http://www.mikesdotnetting.com/article/98/ajax-with-classic-asp-using-jquery

然而,我认为这篇文章中的方法应该是可行的,但我很困惑为什么我的代码只能在localhost和其他web服务器上工作,而不能在1App中工作。以下是我的代码:

ASP:

if request.QueryString("action")="CostUpdate" then
Response.ContentType = "application/json"
a = request.form("GI")
b = request.form("GP")
c = request.form("NA")

Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select * From Cost where CostDate = #" & date() & "# and CostItem ='" & a & "'"
rs.open sql,conn,1,3
if rs.eof then
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select * From Cost"
rs.open sql,conn,1,3
rs.addnew
rs("CostDate")=date()
rs("CostItem")=a
rs("CostAmount")=c
rs("CostNumber")= b * c
rs.update
else
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select * From images where CostDate =#" & adid & "# and CostItem = " & a
rs.open sql,conn,1,3
rs("CostAmount")=c
rs("CostNumber")=b * c
rs.update
end if
end if

JS-

var $GoodsId = $("#costtable tbody").find("tr").eq(c).find("input").eq(1).val();
    var $GoodsPrice = $("#costtable tbody").find("tr").eq(c).find("input").eq(2).val();
    var $NewAmount = $("#costtable tbody").find("tr").eq(c).find("input").eq(3).val();
    $.ajax({
        url: 'work.asp?action=CostUpdate',
        type: "POST",
        data: {
            GI: $GoodsId,GP: $GoodsPrice,NA: $NewAmount
        },
        dataType: "json",
        error: function (xhr, status, error) {
            console.info("CallAjax");
            console.info('An error occured.. ' + xhr.responseText + '..' + error);
        },
        success: function () {
            console.info("Sucess");
        }
    });

asp代码中存在以下几个问题:

  1. rs仍然打开时,不要打开新的sql命令。所以我创建了一个要在if块内部使用的新记录集(rs2)
  2. 你不需要为每个动作重新创建rs。所以我删除了重复创建对象
  3. 不需要将contentType设置为Json,因为不会生成任何数据。您只是在更新数据库
  4. 如果要使用sql update命令,请使用rs.open sql,objcon,2,2
  5. 使用rs.close设置rs=nothing释放服务器内存
  6. 参数adid没有定义。你在别的地方定义过它吗
  7. 您正在数据发布到asp页面,而不是获取。所以你必须使用在第一行请求.form,并在发布的数据中发送参数"action"
  8. 这是整个asp代码吗?您在哪里定义conn

此外,错误"输入意外结束"不是ASP错误。您可能忘记了JavaScript代码内部的}。所提供的代码是可以的,请检查整个代码。

if request.form("action")="CostUpdate" then
a = request.form("GI")
b = request.form("GP")
c = request.form("NA")

Set rs = Server.CreateObject("ADODB.Recordset")
Set rs2 = Server.CreateObject("ADODB.Recordset")
sql = "Select * From Cost where CostDate = #" & date() & "# and CostItem ='" & a & "'"
rs.open sql,conn,1,3
if rs.eof then
sql = "Select * From Cost"
rs2.open sql,conn,2,2
rs2.addnew
rs2("CostDate")=date()
rs2("CostItem")=a
rs2("CostAmount")=c
rs2("CostNumber")= b * c
rs2.update
rs2.close
else
sql = "Select * From images where CostDate =#" & adid & "# and CostItem = " & a
rs2.open sql,conn,2,2
rs2("CostAmount")=c
rs2("CostNumber")=b * c
rs2.update
rs2.close
end if
rs.close
end if
set rs=nothing
set rs2=nothing