码迷,mamicode.com
首页 > Web开发 > 详细

jQuery发送ajax请求三种方式

时间:2015-07-08 18:02:07      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

<button>点击发送ajax get请求</button>

<button>点击发送ajax post请求</button>

<button>点击发送通用的ajax请求</button>

<script type="text/javascript" src="jquery-1.8.3.min.js"></script>

<script type="text/javascript">

get方法发送请求

$(‘button‘).eq(0).click(function(){

//发送ajax请求   

$.get(‘1.php‘,{a:100,b:200},function(data){

alert(data);

})

})

  post发送发送请求

$(‘button‘).eq(1).click(function(){

$.post(‘1.php‘,{a:100,b:200},function(data){

alert(data);

})

})

//通用ajax请求方法

$(‘button‘).eq(2).click(function(){

var a = 100;

$.ajax({

url: ‘1.php‘,

type: ‘GET‘,

data: {a:‘love‘,b:‘you‘},

async: true,

// dataType: ‘json‘,

success: function(data){

a=200;

// alert(data);

},

error:function(){

alert(‘error‘);

},

timeout: 300

});

alert(a);

})

</script>

jQuery发送ajax请求三种方式

标签:

原文地址:http://www.cnblogs.com/dai-idiot/p/4630705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!