ajax的使用方法
后台在写代码时 一般都会用到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的使用方法的更多相关文章
- ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)
一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...
- 在Asp.Net MVC中用Ajax回调后台方法
在Asp.Net MVC中用Ajax回调后台方法基本格式: var operData = ...; //传递的参数(action中定义的) var type = ...; //传递的参数(action ...
- 在Visualforce page中用自带的控件实现Ajax回调后台方法(并且可以用js去动态给parameters赋值)
这里用的组合是:apex:commandLink + apex:actionFunction + apex:outputPanel 这里的 apex:commandLink 和 apex:actio ...
- asp.net如何在前台利用jquery Ajax调用后台方法
一 :最近因为帮同事开发项目使用到了asp.net,而我又想实现Ajax异步请求....从网上查询了一下资料之后,原来在asp.net中利用Ajax调用后台方法同样很简单,为了便于自己以后查看,特将此 ...
- 011_URL和Ajax辅助器方法
创建基本的链接和URL 在我们介绍链接或URL之前先做一些准备,我们这部分要介绍的知识将要使用的项目就是之前建立的HelperMethods项目,现在需要先为其添加一个People控制器,并在其中定义 ...
- 【转】Ajax中send方法参数的使用(get/post)
Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...
- Ajax请求内嵌套Ajax请求的方法
前段时间做项目,需要把全国省市的两个XML文件整合成一个JSON格式的数据,手写的话觉得数据太多了,而且容易出错,于是就想到了用Ajax嵌套的方法来解决,就想平时用Ajax的方法直接嵌套,都会先读出外 ...
- Ajax的ActionLink方法(适用于异步加载)
8.2.1 AJAX的ActionLink方法 在Razor视图中,AJAX辅助方法可以通过Ajax属性访问.和HTML辅助方法类似,Ajax属性上的大部分AJAX辅助方法都是扩展方法(除了Ajax ...
- Ajax的load方法演示
load方法的参数形式为: load(url,[data],[callback]); 其中url为请求HTML页面的URL地址.[data]表示发送至服务器的key/value数据.callback表 ...
- Ajax中send方法的使用
Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...
随机推荐
- LaTeX 课本、LaTeX 学习方法、LaTeX 入门(2)
1. 关于TeX,LaTeX,MikTex,CTeX等的区别 2. 课本 课本1 >> 下载链接:复制链接到迅雷或IDM下载很快 课本2 >> 下载链接:复制链接到迅雷或IDM ...
- 使用keepalived实现kubenetes apiserver高可用
# 安装 nginx yum install nginx -y # 配置nginx4层代理 /etc/nginx/nginx.conf stream { upstream kube-apiserver ...
- django使用pyecharts(5)----django加入echarts_增量更新_定长
五.Django 前后端分离_定时增量更新图表定长数据 1.安装 djangorestframework linux pip3 install djangorestframework windows ...
- Python--拦截接口
- PB笔记之数据窗体分组合计列
- Eclipse RCP难点:给Command传递参数(Object)
这个问题网络上没有答案,国外网站上也没有,本人研究了一天,终于搞明白如何实现,实际上是Eclipse RCP的ICommandService本身就已经提供的方法,只是网络上教的都是使用IHandler ...
- centos yum安装与配置vsFTPd FTP服务器(转)
vsftpd作为FTP服务器,在Linux系统中是非常常用的.下面我们介绍如何在centos系统上安装vsftp. 什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- RuntimeError: Model class users.models.UserProfile doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Django启动的时候报错 File "/home/hehecat/PycharmProjects/MxShop/MxShop/urls.py", line 23, in from ...
- [转载]Python 包管理工具
[转载]Python 包管理工具 最近由于机缘巧合,使用各种方法安装了一些Python包,所以对Python的包管理开始感兴趣.在网上找到一篇很好的文章:https://blog.zengrong.n ...
- Pytorch:module 'torch' has no attribute 'bool'
Pytorch:module 'torch' has no attribute 'bool' 这个应该是有些版本的Pytorch会遇到这个问题,我用0.4.0版本测试发现torch.bool是有的,但 ...