HTML5 Data Bindings Support Product Page

Answered

Usage with PHP generated json

Asked 31 Oct 2013 06:00:49
1
has this question
31 Oct 2013 06:00:49 James Thompson posted:
I am having issues with php generated json.
Any json we create does not load. The only way we found that there was a problem wa using a behavior.
I created an "On Error" behavior and it is being triggered even with this simple PHP generated json
This is the PHP.

<?php 
header('Content-Type: application/json');
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
echo '';
?>

If I take the generated json and put in in a file and use it as a data source the error in not triggered
The URL for the datasource is;
recruitping.com/api/simplejson.php

Can any one help.

Replies

Replied 31 Oct 2013 08:37:58
31 Oct 2013 08:37:58 George Petrov replied:
Hi James,

We actually changed the JSON in the latest HTML5 Data Bindings, to use JSONP so it can be executed across domains and also avoid bad caching you IE.

So you just need to adjust your PHP to return also JSONP compliant JSON. It is just an extra prefix.

See:
www.geekality.net/2010/06/27/php-how-to-easily-provide-json-and-jsonp/

Greetings,
George
Replied 31 Oct 2013 10:33:57
31 Oct 2013 10:33:57 Miroslav Zografski replied:
Hello James,

Try returning a JSONP object. How to generate such in your case:

<?php   
    header('Content-Type: text/javascript; charset=utf8');    
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); 
$callback = $_GET['callback']; 
echo $callback.'('. json_encode($arr).')'; 
?> 


Regards.

Reply to this topic