后台在写代码时 一般都会用到AJAX传值的方法

了解的AJAX方法有三种样式

第一

$.ajax(
{
type: "POST",
url: "UserList.ashx?action=Del",
data: { FId: FId },
contentType: "application/x-www-form-urlencoded",
dataType: "json",
async: false,
cache: false,
success: function (data) {
debugger;
if (data.state) {
//提示并刷新页面
swal({
title: data.msg, //弹出框的title
type: "warning", //淡出框类型
showCancelButtun: false,//是否显示取消按钮
confirmButtonColor: "#DD6B55",//确定按钮颜色
confirmButtonText: "确定", //确定按钮上面的文档
closeOnConfirm: true,
timer: 1000,
},
function (isConfirm) {
window.location.href = data.url;
}
);

}
else {
swal({
title: data.msg, //弹出框的title
type: "warning", //淡出框类型
showCancelButtun: false,//是否显示取消按钮
confirmButtonColor: "#DD6B55",//确定按钮颜色
confirmButtonText: "确定", //确定按钮上面的文档
closeOnConfirm: true,
timer: 1000,
},
function (isConfirm) {
window.location.href = data.url;
}
);
}
},
error: function () {
swal({
title: "服务器异常", //弹出框的title
type: "waring", //弹出框类型
showCancelButton: false, //是否显示取消按钮
confirmButtonColor: "#DD6B55",//确定按钮上面的文档
closeOnConfirm: true

});
}

第二种  传递封装包

$.ajax(
{
type: "POST",
url: "SortList.ashx?action=Add",
data: imgData,
contentType: false,
dataType: "json",
processData: false,
async: false,
cache: false,
success: function (data) {
debugger;
if (data.state) {
//提示并刷新页面
swal({
title: data.msg, //弹出框的title
type: "success", //弹出框类型
showCancelButton: false,//是否显示取消按钮
timer: 1000,
}, function (isConfirm) {
window.location.href = data.url;
}
);

}
else {
swal({
title: data.msg, //弹出框的title
type: "warning", //淡出框类型
showCancelButtun: false,//是否显示取消按钮
confirmButtonColor: "#DD6B55",//确定按钮颜色
confirmButtonText: "确定", //确定按钮上面的文档
closeOnConfirm: true,
timer: 1000,
},
function (isConfirm) {
window.location.href = data.url;
}
);
}
},
error: function () {
swal({
title: "服务器异常", //弹出框的title
type: "waring", //弹出框类型
showCancelButton: false, //是否显示取消按钮
confirmButtonColor: "#DD6B55",//确定按钮上面的文档
closeOnConfirm: true

});
}
})

第三种  给前台传递图片信息

<script type="text/javascript">
$(function () {
//请求后台
$.ajax({
type: "POST",
url: " Products.aspx?action=NewImg",
data: {},
contentType: "application/x-www-form-urlencoded",
dataType: "json",
async: false,
cache: false,
success: function (data) {
if (data.state) {
//将data.data转换为JSON对象
var ImgList = JSON.parse(data.data);
console.log(ImgList);
//构造图片列表HTML
var imglist
for (var i = 0; i < ImgList.lenth; i++) {
imglist = imglist + '<div class="col-md-4"><div class="yc"><img src="' + ImgList[i].FImg + '" class="img-w-100" /></div ><p class="img-m--30">' + ImgList[i].FName + '</p></div >';
}
$("#imglist").html("");
$("#imglist").append(imglist);
}

}
});
})
</script>

第一种跟第二种的区别在于Data  传递后再次解析与不解析

ajax的使用方法的更多相关文章

  1. ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)

    一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...

  2. 在Asp.Net MVC中用Ajax回调后台方法

    在Asp.Net MVC中用Ajax回调后台方法基本格式: var operData = ...; //传递的参数(action中定义的) var type = ...; //传递的参数(action ...

  3. 在Visualforce page中用自带的控件实现Ajax回调后台方法(并且可以用js去动态给parameters赋值)

    这里用的组合是:apex:commandLink  + apex:actionFunction + apex:outputPanel 这里的 apex:commandLink 和 apex:actio ...

  4. asp.net如何在前台利用jquery Ajax调用后台方法

    一 :最近因为帮同事开发项目使用到了asp.net,而我又想实现Ajax异步请求....从网上查询了一下资料之后,原来在asp.net中利用Ajax调用后台方法同样很简单,为了便于自己以后查看,特将此 ...

  5. 011_URL和Ajax辅助器方法

    创建基本的链接和URL 在我们介绍链接或URL之前先做一些准备,我们这部分要介绍的知识将要使用的项目就是之前建立的HelperMethods项目,现在需要先为其添加一个People控制器,并在其中定义 ...

  6. 【转】Ajax中send方法参数的使用(get/post)

    Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...

  7. Ajax请求内嵌套Ajax请求的方法

    前段时间做项目,需要把全国省市的两个XML文件整合成一个JSON格式的数据,手写的话觉得数据太多了,而且容易出错,于是就想到了用Ajax嵌套的方法来解决,就想平时用Ajax的方法直接嵌套,都会先读出外 ...

  8. Ajax的ActionLink方法(适用于异步加载)

    8.2.1  AJAX的ActionLink方法 在Razor视图中,AJAX辅助方法可以通过Ajax属性访问.和HTML辅助方法类似,Ajax属性上的大部分AJAX辅助方法都是扩展方法(除了Ajax ...

  9. Ajax的load方法演示

    load方法的参数形式为: load(url,[data],[callback]); 其中url为请求HTML页面的URL地址.[data]表示发送至服务器的key/value数据.callback表 ...

  10. Ajax中send方法的使用

    Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...

随机推荐

  1. Python中nonlocal的用法

    class Text: def __init__(self): pass def big(self): n, m = 0, 0 def a(): nonlocal n n += 1 print(n) ...

  2. 05 多继承、object类

    多继承 Python中一个类可以继承多个父类,并且获得全部父类的属性和方法. class A: def demo(self): print("demo") class B: def ...

  3. go context 源码分析

    WithCancel func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { c := newCancelCtx(pare ...

  4. Hi3531a海思logo加载的实现流程

    海思篇之开机logo的加载(Hi3531a命令版) 2019-02-02 11:31:51 Wilburn0 阅读数 479更多 分类专栏: 海思开发   版权声明:本文为博主原创文章,遵循CC 4. ...

  5. gulp做的前端代码压缩报错,揭示具体错误 信息

    用gulp做的前端代码压缩,今天在打包的时候发现打包出错了.报的错误是--unable to minify JavaScript.但是至于为什么会不能打包,表示很困惑,然后通过一番搜索,最后得出了问题 ...

  6. IDEA使用技巧--将本地项目和git远程项目关联

    之前开发没有从头儿搭建过新项目,都是从IDEA配置下项目的git地址,pull代码之后进行开发,提交.这次需要将本地新建的项目push到在git上同样是新建的空项目上去(git上的项目只有工程名和re ...

  7. Asp.Net Mvc 整站Https

    网站要使用https需要如下几个步骤 1.申请https证书,现在已经有很多免费的https证书申请了 2.服务器中安装证书 3.网站的连接全部改为https连接 Asp.Net Mvc网站中整站改为 ...

  8. "多层感知器"--MLP神经网络算法

    提到人工智能(Artificial Intelligence,AI),大家都不会陌生,在现今行业领起风潮,各行各业无不趋之若鹜,作为技术使用者,到底什么是AI,我们要有自己的理解. 目前,在人工智能中 ...

  9. iOS testflight 使用说明

    一.告知开发者苹果手机的账户邮箱 1.通过任何形式告知即可 2.下载testflight 二.开发者发送激活邮件到测试者的账户邮箱 1.进入邮箱查看邮件点击 Accept invitation 进行下 ...

  10. echarts的一点记录

    echart官网地址: https://www.echartsjs.com/index.html echarts实例地址:https://echarts.baidu.com/examples/ vue ...