asp.net中js和jquery调用ashx的不同方法分享
程序员文章站
2024-03-02 15:46:46
=============js================复制代码 代码如下:var xhr = new xmlhttprequest(); &n...
=============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%>';
}
}
})