JavaScript怎么获取服务端返回的json?

如题所述

第1个回答  2022-06-28

用jquery的ajax组件可以很快实现js发送请求。参考以下JS代码:


<script>

$(function(){

var url = "http://abc.com";//你的请求url

//发起get请求

$.get(url, function(res){

    console.log('ajax_get========', res);

},'json');

});

//发起post请求

var postdata = {

'id':'123'

};//post提交的参数

$.post(url, postdata, function(res){

    console.log('ajax_get========', res);

},'json');

});

</script>

相似回答