jQuery Ajax + 经典 ASP return 错误 'unexpected end of input'
jQuery Ajax + Classic ASP return error 'unexpected end of input'
这个组合我有两个问题。
在Ajax之后总是return错误(输入意外结束),在localhost中它仍然可以成功保存日期,似乎不是什么大问题。
该代码在我的本地主机上有效,但在 1App Server 中无效(http://www.1apps.net/), I had tried to submit a technique question and them had a response quickly with this way http://www.mikesdotnetting.com/article/98/ajax-with-classic-asp-using-jquery
不过,我认为那篇文章中的方法应该有效,但我很困惑为什么我的代码只能在本地主机和其他网络服务器上工作,而不能在 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代码中存在几个问题:
- 当 rs 仍然打开时,不要打开新的 sql 命令。所以我创建了一个
在 if 块中使用的新记录集 (rs2)。
- 您不需要为每个操作重新创建 rs。所以我删除了重复
创建对象。
- 不需要将contentType设置为Json,因为不会生成数据。您只是在更新数据库。
- 当您想使用 sql 更新命令时,请使用 rs.open sql,objcon,2,2。
- 使用 rs.close 并设置 rs=nothing 以释放服务器内存。
- 参数 adid 没有定义。你在别处定义了吗?
- 您正在发布 数据到asp 页面,而不是正在获取。所以你必须使用
request.form 在第一行并在发布的数据中发送参数 "action"。
- 这是完整的 asp 代码吗?你在哪里定义conn?
此外错误 "unexpected end of input" 不是 ASP 错误。你可能忘记了 } inside 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
这个组合我有两个问题。
在Ajax之后总是return错误(输入意外结束),在localhost中它仍然可以成功保存日期,似乎不是什么大问题。
该代码在我的本地主机上有效,但在 1App Server 中无效(http://www.1apps.net/), I had tried to submit a technique question and them had a response quickly with this way http://www.mikesdotnetting.com/article/98/ajax-with-classic-asp-using-jquery
不过,我认为那篇文章中的方法应该有效,但我很困惑为什么我的代码只能在本地主机和其他网络服务器上工作,而不能在 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代码中存在几个问题:
- 当 rs 仍然打开时,不要打开新的 sql 命令。所以我创建了一个 在 if 块中使用的新记录集 (rs2)。
- 您不需要为每个操作重新创建 rs。所以我删除了重复 创建对象。
- 不需要将contentType设置为Json,因为不会生成数据。您只是在更新数据库。
- 当您想使用 sql 更新命令时,请使用 rs.open sql,objcon,2,2。
- 使用 rs.close 并设置 rs=nothing 以释放服务器内存。
- 参数 adid 没有定义。你在别处定义了吗?
- 您正在发布 数据到asp 页面,而不是正在获取。所以你必须使用 request.form 在第一行并在发布的数据中发送参数 "action"。
- 这是完整的 asp 代码吗?你在哪里定义conn?
此外错误 "unexpected end of input" 不是 ASP 错误。你可能忘记了 } inside 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