jQuery发送ajax请求三种方式

<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>

posted @ 2015-07-08 16:56  永远的呆  阅读(4658)  评论(0编辑  收藏  举报