Phonegap ajax GET返回内部服务器错误



我正在用Phonegap和Backbone构建一个应用程序,该应用程序解析外部XML提要。进料位置:

http://cbccork.schoolspace.ie/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw

我用提取

var news = new model.NewsCollection();
news.fetch({
full_url: true,
success: function (collection) {
slider.slidePage(new NewsList({collection: collection}).$el);
},
error: function (model, response, options) {
console.log('statusText is ');
console.log(response.statusText);
console.log('responseText is ');
console.log(response.responseText);
},
});

这很好用。然而,子域将很快被删除,因此提要url将变为:

http://cbccork.ie/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw

如果你转到url,你会看到输出是相同的xml(http://cbccork.ie/而不是http://cbccork.schoolspace.ie/)。

然而,在Android设备上进行测试时,不会返回任何结果。我打印出的回复是:

Value of responseText is 
Value of responseXML is null
Value of status is 500
Value of statusText is Internal Server Error

我已经在chrome中测试过了(通过禁用同源策略),它是有效的。但在任何安卓设备上,它都不会工作。

我已经试着解决这个问题三天了,但完全被难住了。有什么想法吗?

编辑

新闻模型和集合如下:

define(function (require) {
"use strict";
var $                   = require('jquery'),
Backbone            = require('backbone'),
id=1,
xml,
parsed = [], 
title = "", 
description = "",
pubDate = "", 
src="",
img="",
News = Backbone.Model.extend({  
}),

NewsCollection = Backbone.Collection.extend({
model: News,
//url: 'http://www.test.webintelligence.ie/test/',
url: 'http://www.cbccork.ie/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw',
//This is used so I can test on a browser. On a device, use the direct link   
/*
url: function(){
console.log('in news');
return "/school-proxy.php?type=news";
},*/

parse: function (data) {
xml = data;

$(xml).find('item').each(function (index) {

img = $(description).find('img:first');
src = img.attr('src');
if(typeof(src)==='undefined' || src===null || src===""){
//so its null or undefined
src = "img/crest.jpg";
}
title = $(this).find('title').text();
description = $(this).find('description').text();
pubDate = $(this).find('pubDate').text();
pubDate = pubDate.substring(0, pubDate.length-12);

parsed.push({id:id, title: title, 
description:description, pubDate:pubDate, src:src});
title, description, pubDate, src, img = "";
id++;
});
return parsed;
},

fetch: function (options) {
options = options || {};
options.dataType = "xml";
return Backbone.Collection.prototype.fetch.call(this, options);
}
});

return {
News: News,
NewsCollection: NewsCollection
};
});

编辑:

我尝试了直接调用Ajax,但在Android设备上再次出现内部服务器错误:

$.ajax({
url: "http://www.cbccork.ie/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw",
})
.done(function( data ) {
console.log( "Sample of data:", data );
})
.fail(function( jqXHR, textStatus, errorThrown ) {
console.log('in the fail, textstatus is ');
console.log(textStatus);
console.log('error throwen is ');
console.log(errorThrown);
});

有什么办法解决这个问题吗?我什么都试过了。。。

刚刚在我的电脑上尝试了一下,结果是:

XMLHttpRequest cannot load http://www.cbccork.ie/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.2.121' is therefore not allowed access. 

毫无疑问,您的服务器没有针对CORS进行配置。您不仅必须允许您的脚本访问其他域,而且您的服务器还应该配置为可以从其他域访问。

您是否尝试过通过ajax get获取xml并转换为JSON以使其更容易?

也许找出错误会有所帮助。

Joomla Mobile插件已打开,但配置不正确,这意味着从移动设备查询时没有返回xml。

最新更新