无法从URL获取JSON数组
Can't get JSON array from URL
我正在使用Resteasy,我已经在URL中启动了一个资源:'localhost:8080/resources/agents '
当我在浏览器中测试时,我得到:[{"agence":"Agence Kettani","ville":"Agadir","adresse":"Cartier Hassan II, Agadir","tel":"0528252828","fax":null,"idBanque":1,"id":1},
{"agence":"Abbatoire","ville":"Agadir","adresse":"Abbatoire, 358 ","tel":"0528283569","fax":null,"idBanque":2,"id":2}]
但是当我尝试用jQuery获取数组时,我得到这个:
readyState
0
responseText
""
status
0
statusText
"error"
abort
function()
always
function()
complete
function()
done
function()
error
function()
fail
function()
getAllResponseHeaders
function()
getResponseHeader
function()
isRejected
function()
isResolved
function()
overrideMimeType
function()
pipe
function()
promise
function()
setRequestHeader
function()
statusCode
function()
success
function()
then
function()
这是我在Firebug中所做的:
$.get('http://localhost:8080/Paie1Web/ressources/agences', function(data) {
return alert(data);
});
我已经测试了getJSON
和AJAX。我怎样才能纠正这个问题呢?
有时在成功时,ajax有效负载还没有加载,由于延迟,服务器减速,等等,所以你需要处理,你可以使用complete或done(取决于你正在使用的版本),也许像这样:
var payload = {};
$.get('http://localhost:8080/Paie1Web/ressources/agences', function(data) {
$.extend(
true, //this forces the object to be deep copied
payload, //the target object to extend
data //Extend to this object
);
}, 'json').complete(function(){
//do what ever you want here with the extended payload
});
我想这样可以
相关文章:
- 需要帮助设置json数组
- 如何使用 node.js 比较两个 json 数组
- 根据id将json数组组合为一个json数组
- 如何创建JSON数组
- 如何将package.json数组传递给grunt.js
- 访问json数组中的对象
- JSON数组数据返回Undefined
- 如何向JSON数组动态添加属性
- 如何从json数组中获取特定值
- 从多维嵌套json数组创建下拉列表
- 在ListView中添加JSON数组中存储的图像-ReactNative
- jquery在json数组中循环
- 将 JSON 数组解析为 JavaScript 数组
- 如何在php中读取没有任何键的JSON数组
- 如何在Jquery中迭代JSON数组
- 如何在cycle js中从JSON数组创建组件
- 如何使用jquery返回php-json数组对象
- JSON数组转换为JS对象数组
- 使用System从C#集合创建JSON数组.网状物剧本序列化
- 使用Underscore.js修改json数组中所选元素的更有效方法