Welcome Guest, Not a member yet? Register   Sign In
JSON service provided by CI [SOLVED]
#1

[eluser]Brian Loomis[/eluser]
We have an application that was written in CodeIgniter, that produces JSON that is consumed by an EE app. When we have a call with jQuery to this JSON as a file it works fine, a sample file which was created by cutting and pasting JSON from the browser of the CI web service.

However, when we include the URL to the JSON call in CI from EE, EE does not like the JSON and will not parse it. The logs for nginx show 200's for all the results as coming from the EE app and nothing ends up in the error logs. Similarly there are no failures in the nginx logs for the EE site, only 200's for all resources.

I'm going to have our designer and ee coder post some code to this thread, but want to see if anyone has any ideas, about includes. XSS issues consuming CI services from another domain, EE issues, or nginx mimetype problems.

Stay Tuned.
#2

[eluser]Unknown[/eluser]
The json is loaded with jQuery and written to the EE template, but EE has already done it's parsing. So I don't think that can be the problem.

a local url works
Code:
var jsonURL = '/assets/json/example.json';

But from another ip it doesn't:
Code:
var jsonURL = 'http://999.999.999.999/thing/19/10';

the jQuery is pretty straightforward
Code:
$.getJSON(jsonURL,
    function(data) {
        $.each(data.faults, function(i,fault) {
            do stuff
        });
      );

    }
);

I am suspecting it has something to do with the remote url, so I am looking into doing a jsonp call and add
Code:
callback=?
to the url. When I do that I get a CI error: 'The URI you submitted has disallowed characters.'

hmmmm....
#3

[eluser]Brian Loomis[/eluser]
So it seems as we're working on this, nginx returns 200's for the JSON call whether we do it from a browser or from jQuery. CodeIgniter seems to send off the JSON fine, but jQuery seems to never be able to do anything with it.
#4

[eluser]codylindley[/eluser]
Note: JSONP is an extension of the JSON format, requiring some server-side code to detect and handle the query string parameter. More information about it can be found in the original post detailing its use.

When data is retrieved from remote servers (which is only possible using the script or jsonp data types), the operation is performed using a [removed] tag rather than an XMLHttpRequest object. In this case, no XMLHttpRequest object is returned from $.ajax(), nor is one passed to the handler functions such as beforeSend.
#5

[eluser]codylindley[/eluser]
see the end of this article.

http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
#6

[eluser]Brian Loomis[/eluser]
from Chrome dev toolbar:
XMLHttpRequest cannot load http://192.168.100.192/device/summary/19/10. Origin http://www.xyz.com is not allowed by Access-Control-Allow-Origin.

http://serverfault.com/questions/162429/...n-in-nginx


location \ {
add_header Access-Control-Allow-Origin *;
}

This solved the issue.




Theme © iAndrew 2016 - Forum software by © MyBB