|
|
html代码:<input type="text" name="userName"/><br/> <input type="button" name="check" id="check"> 对客户端的数据进行判断,如果输入的字符串为"123"则在页面上显示"true";
如下:用简单的$.get方式代替复杂$.ajax的操作,当请求成功时可调用回调函数;
jquery代码: $(document).ready(function() {$("#check").click(onclick);//绑定button按钮,添加click事件} ) onclick(data,status){}function onclick(){$.get("check.do",{"userName":$("#userName").val()},function(data,textStatus){this;alert(this)//this是指ajax的相关信息alert(data);//json数据({:}这种键值对方式)alert(textStatus);//状态码} )} post方式:$.post(url,data,callback,datatype) url 为请求路径 data 参数格式 {参数名:参数}{name:"fisher"} callback 回调函数 datatype 返回数据的类型 (html,xml,json)方法与get方式差不多,后台的处理部分注意要有关闭 或者刷新操作 Response.Flush(); Response.close(); |
|