关于ajax的JQuery使用

jQ的常用方式有:
$.ajax(options)把远程数据加载到 XMLHttpRequest 对象中
$.get(url,data,callback,type)使用 HTTP GET 来加载远程数据
$.post(url,data,callback,type)使用 HTTP POST 来加载远程数据
$.getJSON(url,data,callback)使用 HTTP GET 来加载远程 JSON 数据
$.getScript(url,callback)加载并执行远程的 JavaScript 文件


我们往往使用了$.post(),先是提交了数据,这里它使用以下方式提交,后端做了数据入库验证,接着就使用了data获取返回值,再做页面决定

往往前端会先做验证,这是验证的锦上添花。。

				$.post(
					"register_login!register.do",
					{"username":user,"password1":pass1,"password2":cpass,"email":email,"telphone":tel}
					,
					function(data){

						if(data==1)
						{
							
							window.location.href="index.jsp";
							
						}
						else
						{
							alert("信息填写错误");

						}

					}
			
				);

$.post("XXXX.do",{ "username":user,"password1":pass1} ,function( returncode)  {   }     );

而$.ajax原理一样,也是发了数据,再获取data码,再做页面跳转决定的。


 $.ajax({
            url: "/order/doOrder",
            type: "POST",
            data: { productid: self.productid(), productname: self.productname(), price: self.price(), count: self.count(), username: self.username() },
           success: function (data) {
                        if (data.code == 1) {
                            location.href = location.href;
                        }
                        else
                            alert(data.code);
                    }
                })





你可能感兴趣的:(ajax)