I am pretty new to the concept of JSON/JSONP so i guess I am just missing something very obvious.
I try to figure out how to invoke a JSONP request to a .php script, which in return should provid me with some simple JSON data.
This is my .php script:
PHP Code:
<?php
$callback = $_REQUEST['callback'];
$data =
'[
{ "id": 1,
"name": "Orankesee",
"additional": "abc",
"url": "www.url.de",
"creator": "Beide" },
{ "id": 2,
"name": "Tanzen gehen",
"additional": "abc",
"url": "www.url.de",
"creator": "Valeska" },
]';
if ($callback) {
header('Content-Type: text/javascript');
echo $callback . '(' . $data . ');';
} else {
header('Content-Type: application/x-json');
echo $data;
}
?>
as you can see, pretty straight forward.
Now if I attach a jsonp store proxy that calls this script, everything seems to work fine, the JSON data gets loaded into my store, which is then displayed correctly in a view.
Here is the code of that proxy:
Code:
proxy: {
type: 'jsonp',
url: 'http://mydomain.com/hosted/test.php',
reader: {
type: 'json'
}
}
Now if i try to invoke that .php-Skript on my own, I try something like this:
Code:
jsonpTest: function(){
console.log('jsonpTest started!');
Ext.util.JSONP.request({
url: 'http://mydomain.com/hosted/test.php',
callbackKey: 'callback',
callback: function (jsonData) {
console.log('jsonpTest raw:', jsonData);
console.log('jsonpTest parsed:', Ext.decode(jsonData));
}
});
}
This function seems to legitimately call the .php script, but if i debug the returned data (jsonData) all it seems to contain is the value 'true'.
Am I missing a second parameter on the callback function, one that contains the response, while I am just getting returned that the request itself worked or something?