<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="js/jquery.js"></script> <script> $(function(){ $('#btnok').bind('click',function(){ //发送ajax请求 $.ajax({ type:'get', url:'ajax1.php', cache:false, success:function(msg){ alert(msg); } }); }); }); </script> </head> <body> <input type="button" id="btnok" value="OK" /> </body> </html>
php的示例代码以下:php
<?php echo "hello jQ";
① Ajax的底层实现 ② Ajax的高级实现html
jQuery.ajax(options)或$.ajax(options)jquery
参数说明:ajax
options:要求参数是一个json对象,内容以下:json
async :是否异步,默认为true缓存
cache :是否缓存,默认为true异步
complete :当Ajax状态码为4时,所触发的回调函数async
contentType :设置请求头函数
data :发送Ajax请求时,所传递的参数,要求是一个字符串post
dataType :期待的返回值类型,text,xml,json,jsonp,默认为text
success :当Ajax状态码为4且响应状态码为200时,所触发的回调函数
type :模拟http请求中的get或post方法
url :请求的url地址