jQuery ajax使用$(this).parent()无效解决方法

2018-01-20网页设计
218

鼠标点击"remove"链接,根据ajax的返回值删除页面父元素块。

做法如下:


$('.remove').bind('click',function(){
	var div = $(this).parent(); //先获取父级元素
	$.ajax({
		type:'post',
		url:$(this).attr('href'),
		dataType:'json',
		data:{id:$(this).attr('id')},
		success:function(msg){
			if(msg.error==0){
				alert(msg.msg);
			}else{
				div.remove(); //再删除
			}
		}
	});
	return false;
});

The End
ajax

相关推荐

解决ajax http请求https的办法
ajax请求路径是https的时候,如果服务器没有配置ssl证书,访问此页面时,浏览器控制台会显示SSL ERROR,和一些其他错误,但请求路径是http是,则不会报错 ajax是ajax的post方法 解决办法:在post方法中加上异步参数(async:false)表示ajax是同步的,就行了...
2018-05-02 网页设计
801

jQuery ajax使用$(this).parent()无效解决方法
鼠标点击remove链接,根据ajax的返回值删除页面父元素块。 做法如下: $(.remove).bind(click,function(){var div = $(this).parent(); //先获取父级元素$.ajax({type:post,url:$(this).attr(href),dataType:json,data:{id:$(this).attr(id)},success:functi...
2018-01-20 网页设计
218

Ajax简单实例创建
XmlHttp是一套可以在Javascript、VbScript、Jscript等脚本语言中通过http协议传送或从接收XML及其他数据的一套API。XmlHttp最大的用处是可以更新网页的部分内容而不需要刷新整个页面。几乎所有...
2017-06-13 网页设计
25

jQuery中的ajax的load()函数读取页面
首先介绍下load()函数: load()函数: 函数介绍:load(url, [data], [callback]) 返回值:jQuery 参数说明: url:待装入 HTML 网页网址。 data:(可选参数)发送至服务器的 key/value 数据。 callback:(可选参...
2017-06-13 网页设计
19

jQuery中的ajax的get()函数读取页面
首先介绍get()函数: url,[data],[callback],[type] 参数说明: url :待载入页面的URL地址 data :待发送 Key/value 参数。 callback :载入成功时回调函数。 type :返回内容格式,xml, html, script, json, text,...
2017-06-13 网页设计
28

jquery ajax POST 例子详解
function test(){ $.ajax({ //提交数据的类型 POST GET type:POST, //提交的网址 url: login.php , //提交的数据 data:{Name:sanmao,Password:sanmaoword}, //返回数据的格式 datatype: html,//xml, html, script, json, jsonp, text //在请求之前调用的函数...
2016-07-15 网页设计
180