Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap ajax GET returning Internal Server Error

Im building an app with Phonegap and Backbone which parses an external XML feed. The feed is at:

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

I fetch with:

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);
    },
});

This works fine. However, the subdomain will be removed soon so the feed url will become:

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

If you go to the urls you will see the output is the same xml (with http://cbccork.ie/ instead of http://cbccork.schoolspace.ie/).

However, when testing on an Android device, nothing is returned. I printed out the response which is:

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

I have tested this in chrome (by disabling the same origin policy) and it works. But on any android device, it will not work.

I have been trying to solve this for 3 days and am completely stumped. Any ideas?

EDIT

The news model and collection looks like this:

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
};

});

EDIT:

I tried a direct Ajax call, but yet again I get an Internal Server Error on an Android device:

        $.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);

            });

Is there any way of solving this? I have tried everything...

like image 522
user1716672 Avatar asked Apr 26 '26 12:04

user1716672


1 Answers

just tried it from my pc and this is the result:

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. 

there is no doubt that your server is not configured for CORS. you not only have to allow your script to access other domains, but your server should also be configured for being accessed from other domains.

like image 64
mohamnag Avatar answered Apr 29 '26 10:04

mohamnag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!