asp.net中js和jquery调用ashx的不同方法分享
编程学习 2021-07-04 22:40www.dzhlxh.cn编程入门
asp.net中js和jquery调用ashx的不同方法分享,需要的朋友可以参考一下
=============js================
var xhr = new XMLHttpRequest();
xhr.open("get", 'Controls/gengCart.ashx?CartID=' + input + '&count=' + inp, true);
xhr.setRequestHeader("If-Modified-Since", "0");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var result = xhr.responseText;
var json = eval("(" + result + ")");
alert(js.name);
}
};
xhr.send(null);
============jquery=====================
$.post('Controls/Cart.ashx', { "productID":<%= GetID %>,"count":"1","userID":'<%= uid %>' }, function (data,statu) {
if (statu == 'success') {
if(data=="false"){
alert("请登录后再进行此操作");
}
else{
window.location="gwc.aspx?uid="+'<%= uid%>';
}
}
})
代码如下:
var xhr = new XMLHttpRequest();
xhr.open("get", 'Controls/gengCart.ashx?CartID=' + input + '&count=' + inp, true);
xhr.setRequestHeader("If-Modified-Since", "0");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var result = xhr.responseText;
var json = eval("(" + result + ")");
alert(js.name);
}
};
xhr.send(null);
============jquery=====================
代码如下:
$.post('Controls/Cart.ashx', { "productID":<%= GetID %>,"count":"1","userID":'<%= uid %>' }, function (data,statu) {
if (statu == 'success') {
if(data=="false"){
alert("请登录后再进行此操作");
}
else{
window.location="gwc.aspx?uid="+'<%= uid%>';
}
}
})