使用jQuery使用REST Web服务 [英] Consume REST web service with jQuery
本文介绍了使用jQuery使用REST Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Web服务,该服务在某个URL上以JSON格式显示数据,我的问题是如何使用jQuery将数据存储在变量中.到目前为止,我已经尝试过了:
I have a web service that displays a data in the JSON format at a certain URL, my question is how can I store this data in a variable using jQuery. I've tried this so far :
$.ajax( {
type:'Get',
url:'http://localhost:8080/demo/x',
success:function(data) {
alert(data);
}
});
但是当我进入放置该脚本的页面时,它不会发出任何警告.
But it doesn't alert anything when I got to the page where I have put this script.
预先感谢您的帮助.
推荐答案
尝试一下:
$.ajax({
type: 'GET',
url: 'http://localhost:8080/demo/x',
data: {
format: 'json'
},
dataType: 'jsonp',
success: function(data) {
alert('Data: ' + data);
},
error: function() {
alert('Error');
}
});
这篇关于使用jQuery使用REST Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文