您有个知识币

【退出】

jquery ajax例子

经常用到jquery ajax,但有时候会忘记怎么写,下面做个笔记。 jquery ajax例子:

//post 方式

$.ajax({

url : 'test.php',

type : 'post',

data : {'act':'addvideo', 'videoname':videoname},//这里使用json对象

success : function(data){

          //code here...

},

fail:function(){

        //code here...

}

});

 

//get 方式

$.get("test.php", { name: "John", time: "2pm" }, function(data){ //code here... });

 

//get 方式2

$.ajax({

url : 'test.php',

data : {'act':'addvideo', 'videoname':videoname},//这里使用json对象

success : function(data){

//code here...

}

});

 

//jquery ajax同步方式

$.ajax({

url : 'test.php',

type : 'post',

async: false,//使用同步的方式

data : {'act':'addvideo', 'videoname':videoname},//这里使用json对象

success : function(data){

//code here...

},

fail:function(){

//code here...

}

});

本文固定链接: http://www.webzhishi.com/jquery-ajax-simple/ | web知识网

jquery ajax例子:等您坐沙发呢!

发表评论