asp.net页面中js如何通过$.post调用ashx文件

ethan永不言弃 2012-10-18 05:19:33
ashx:
public void ProcessRequest(HttpContext context)
{
string falg = "true";
int cid = Convert.ToInt32(context.Request["CartID"]);
Model.MCart mcart = new Model.MCart();
mcart = bcart.GetModel(cid);
mcart.Count = Convert.ToInt32(context.Request["count"]);
bcart.Update(mcart);
context.Response.Write(falg);

}


js调用:
function check3(input) {
var inp = document.getElementById("iup_" + input).value;
var price = document.getElementById("pr_" + input).innerHTML;
document.getElementById("lbl_" + input).innerHTML = parseInt(inp) * parseFloat(price);

$.post('Controls/gengCart.ashx', { "CartID": input, "count": inp }, function (data, statu) {

if (statu == 'success') {

alert(22);
} else {
alert(11);
}
})
}
js里面调用没反应,请问一下是什么原因。
...全文
195 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2012-10-18
  • 打赏
  • 举报
回复
这些代码看不出什么问题,改成下面的结构看看什么问题
    function check3(input) {
var inp = document.getElementById("iup_" + input).value;
var price = document.getElementById("pr_" + input).innerHTML;
document.getElementById("lbl_" + input).innerHTML = parseInt(inp) * parseFloat(price);
//确认你上面3个控件都是存在的
alert('启动ajax'); ////是否执行到这句,如果没有执行那就是上面有控件ID不正确
$.ajax({ url: 'Controls/gengCart.ashx'
, data: { "CartID": input, "count": inp }
, type: 'POST'
, success: function (data, statu) {

if (statu == 'success') {

alert(22);
} else {
alert(11);
}
}
, error: function (xhr) {alert('动态页出错\n'+xhr.status+'\n'+xhr.responseText }
});
/* $.post('Controls/gengCart.ashx', { "CartID": input, "count": inp }, function (data, statu) {

if (statu == 'success') {

alert(22);
} else {
alert(11);
}
})*/
}
oggmm 2012-10-18
  • 打赏
  • 举报
回复
debug一下 看是不是有js错误 然后在看看ashx响应的内容是什么

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧