ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

jsonp encoding

March 04, 2011 1:44pm

Subscribe [3]
  • #1 / Mar 04, 2011 1:44pm

    Robfletcher

    149 posts

    I’m trying to convert my RSS feed from XML to a JSONP format.

    However, when I try to parse the JSONP feed from a EE2 page type of webpage it says “Invalid GET Data”.

    The URL I am using looks something like this:

    /index.php/site/jsonp?callback=?

    Jquery then puts in a string and sends the data back.

    When i view the json feed without the ?callback=? i can see the feed.  Can i add query strings to URL in EE? Is there some setting i need to use?

    Is there also some JSONP plugin maybe that i could use to get my data from my channel into the right format.

  • #2 / Mar 05, 2011 2:01pm

    Greg Salt

    3988 posts

    Hi CDPRfletcher,

    EE can certainly deal with query strings. It looks like you are using an invalid query string format. This should work:

    /index.php/site/jsonp?callback=

    but adding the question mark as the callback value is the problem here.

    I’m not aware of a JSONP plugin. Have you searched Devot://ee?

    Cheers

    Greg

  • #3 / Mar 07, 2011 11:12am

    Robfletcher

    149 posts

    When i add ?callback= to the end of my url, i see the IIS7 404 error. Removing the query string, i can see the feed.

    Maybe you can try this in your version of EE.  With JSONP, i think i have to put that ?callback=?, but i’m not sure. Sort of figuring this out myself.

    JSONP from what i have read should allow me to read my JSON data from anywhere.  Maybe XML is better for this.

    What would you guys use?

    anyway, here is the code i have in a page called “jsonp”, i have PHP enabled on my template and I’m using json_encode to encode my data.

    <?php
    header("content-type: application/json");
    
    $data = array();
    
    {exp:channel:entries channel="myBlog" limit="10" dynamic_start="on"}
    
    
    $data["title"] = "{title}"; 
    $data["link"] = "{comment_url_title_auto_path}";
    {/exp:channel:entries}
    
    print 'parseResponse'. '('.json_encode($data).')';
    
    ?>
  • #4 / Mar 07, 2011 4:26pm

    Ingmar

    29245 posts

    What version and build of EE are you using? Do you’ve got a link to the page / feed? Also, are you using mod_rewrite in any way?

  • #5 / Mar 07, 2011 4:37pm

    Robfletcher

    149 posts

    latest version - v2.1.3.
    no mod_rewrite.

    Its on a dev server on a private link.  Its not a link i want to broadcast.

    can i pm you the link or can u just drop the code i posted into a template and append the qstring to the end and see if you get a 404 error?

    Rob

  • #6 / Mar 08, 2011 3:06am

    John Henry Donovan

    12339 posts

    Rob,

    In your config.php what do you have set for $config[‘uri_protocol’].Try some of the options available

    Is there also some JSONP plugin maybe that i could use to get my data from my channel into the right format.

    There is a plugin here for standard JSON format

    I have had trouble with json_encode in the past. You may find some of the hand rolled encode funtions on the PHP site may work better for you

    The recommended approach would be to use plugin I mentioned or make your own plugin

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases