后台在写代码时 一般都会用到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. C++实现2048小游戏

    代码如下: #define _CRT_SECURE_NO_WARNINGS//去掉编译器内部扩增问题 #include<stdio.h> #include<stdlib.h> ...

  2. Linux基础-10-网络原理和基础设置

    1. 使用ifconfig命令来维护网络 1) ifconfig命令的功能:显示所有正在启动的网卡的详细信息或设定系统中网卡的IP地址. 2) 应用ifconfig命令设定网卡的IP地址: 例如:修改 ...

  3. centos 安装notepad++

    notepad++在linux下名字为notepadqq第一步,还是下载软件库$ sudo wget -O /etc/yum.repos.d/sea-devel.repo http://sea.fed ...

  4. python 之 并发编程(非阻塞IO模型、I/O多路复用、socketserver的使用)

    9.16 非阻塞IO模型 cpu占用率过高 服务端: from socket import * import time s = socket() s.bind(('127.0.0.1',8080)) ...

  5. PAT(B) 1089 狼人杀-简单版(Java)逻辑推理

    题目链接:1089 狼人杀-简单版 (20 point(s)) 题目描述 以下文字摘自<灵机一动·好玩的数学>:"狼人杀"游戏分为狼人.好人两大阵营.在一局" ...

  6. prometheus环境搭建

    1. 下载文件 wget https://dl.grafana.com/oss/release/grafana-6.2.4.linux-amd64.tar.gz tar -zxvf grafana-. ...

  7. 在论坛中出现的比较难的sql问题:24(生成时间段)

    原文:在论坛中出现的比较难的sql问题:24(生成时间段) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所以,觉得有必要记录下来 ...

  8. R_数据视觉化处理_初阶_02

    通过数据创建一幅简单的图像, #Crate a easy photopdf("mygraph.pdf") attach(mtcars) plot(wt,mpg) abline(lm ...

  9. @Transactional 同一个类中无事务方法a()内部调用有事务方法b()的问题

    https://blog.csdn.net/u010235716/article/details/90171802 1. 事务的4种特性       序号 参数 含义1 原子性(Atomicity) ...

  10. Windows下动态库的制作与使用

    创建静态库