gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:15:10 26 4
gpt4 key购买 nike

我正在使用 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);
},
});

这很好用。但是,子域很快就会被删除,因此 feed url 将变为:

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

如果您转到网址,您将看到输出是相同的 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 中对此进行了测试(通过禁用同源策略)并且它有效。但在任何 Android 设备上,它都不起作用。

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

编辑

新闻模型和集合如下所示:

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。您不仅必须允许您的脚本访问其他域,而且您的服务器还应该配置为可以从其他域访问。

关于jquery - Phonegap ajax GET 返回内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20701348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com