*******************************************************************************************************************************
AJAX
$.ajax({
url: url + "?action=setfoodclass",
type: "post",
data: { AAA: aaa, BBB: bbb },
success: function (msg) {
var str = "";
if (msg.replace("[]", "").length > 0) {
msg = eval("(" + msg + ")");
var total = msg.total; //数据总数
var rows = msg.rows;
$(rows).each(function (i) {
str += '<a style="position: relative;">' + rows[i].food_class_name + '<i class="num">0</i></a>';
});
}
$("#tab").html(str);
}
});
$.ajax({
url: url + "?action=orderlist",
type: "post",
data: { user_id: user_id, shopId: shopId, table_No: table_id },
success: function (msg) {
if (msg.replace("[]", "").length > 0) {
//alert(msg);
msg = eval("(" + msg + ")");
if (msg.istatic == 0) {
alert(msg.detailed);
}
if (msg.istatic == 1) {
window.location.href = msg.detailed;
}
}
}
});
Response.Write("{ \"istatic\":\"0\", \"detailed\":\"出错!" + _alpay_Helper.Error + ",请重试!\" }");
Response.End();
return;
Response.Write("<script> alert('请先查询'); </script>");
Response.Write("{ \"istatic\":\"0\", \"detailed\":\"数据丢失, 请重试\" }");
Response.Redirect(url_jump);
Response.End();
$.ajax({
async: true, /*异步 默认true false同步*/
url: "http://isupalipay/intl/merchant/common/monitor.htm",
type: "post",
contentType: 'application/json',
headers:{
"Content-Type": "application/json;charset=utf-8",
"Authorizationr":"Authorizationr",
},
dataType: 'json',
data: da,
success: function (msg) {
console.log(msg);
},
error: function (msg) {
console.log(msg);
},
});
/*form提交*/
var formData = new FormData();
formData.append("uname", username);
formData.append("upwd", password);
formData.append("sid", 0);
formData.append("mid", 2);
$.ajax({
url: "https://demoglobal.eftpay.com.cn/EFT_VIP/api/activity.ashx?act=staff.Login",
type: "POST",
contentType: false,//这里
processData: false,//这两个一定设置为false
data: formData,
success: function (msg) { //成功的回调函数
console.log(msg);
if (msg.replace("[]", "").length > 0) {
//alert(msg);
msg = eval("(" + msg + ")");
if (msg.restate == 0) {
alert(msg.remsg);
}
if (msg.istatic == 1) {
window.location.href = msg.detailed;
}
}
},
error: function (e) {
alert("失败!请重试");
}
});
*******************************************************************************************************************************
AJAX 上传
<img id="user_logo" runat="server" src="" style="max-width: 200px; max-height: 200px;" />
<input type="file" name='file' id="upload_file_logo"/>
<input οnclick="upload_logo()" type="button" value="上传"/><!-- submit -->
<script type="text/javascript">
function upload_logo() {
var formData = new FormData();
formData.append("file", document.getElementById("upload_file_logo").files[0]);
if (document.getElementById("upload_file_logo").files[0].size > (1 * 1024 * 1024)) { //大于1M
alert("图片大小已超限制(≤1M),请重新上传");
return;
}
$.ajax({
url: "CustomerAdd.aspx?act=upload",
type: "POST",
data: formData,
contentType: false, //必须false才会自动加上正确的Content-Type
/**
* 必须false才会避开jQuery对 formdata 的默认处理
* XMLHttpRequest会对 formdata 进行正确的处理
*/
processData: false,
success: function (res) {
if (res.restate == 1) {
alert("上传成功!");
$("#user_logo").attr("src", res.url);
$("#hf_user_logo").val(res.url);
}
else if (typeof (res.remsg) != "undefined" && res.remsg != null) {
alert("上传失败!" + res.remsg);
}
else {
alert("上传失败!");
}
},
error: function (res) {
console.log(res);
alert("上传失败!");
}
});
}
</script>