Jsonp - callback function
Jsonp - callback function
veroval
Posts: 5Questions: 1Answers: 0
Hi,
in this example http://datatables.net/examples/server_side/jsonp.html you don't specify how and where we have to define the callback function.
In the tab "Server-side script" you said:
$jsonp = preg_match('/^[$A-Z_][0-9A-Z_$]*$/i', $_GET['callback']) ?
$_GET['callback'] :
false;
if ( $jsonp ) {
echo $jsonp.'('.json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
).');';
}
But in the tab "Javascript" you don't define neither callback parameter nor function.
I don't have it clear. What I'm doing wrong?
Thanks for your help.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm not sure you are doing anything wrong. The callback function is specified by jQuery when you use the
jsonp
data type. See the jQuery documentation for details.Allan
But I don't have a $_GET['callback'] parameter to use in the server side script.
You would do if you used jQuery to make the JSONP request as it provides that information for you. You'll note in my client-side code that I don't define it either.
Allan
I'm sorry Allan but i continue no understanding.
So should i put in server side only?
Shouldn't I consider the note in the comment tab?
You should do exactly what I have done in the server-side script (which you pasted above). The way JSONP works is to execute a Javascript callback function with the data. jQuery provides that function name.
The comment on the example page you linked to highlights that the "Ajax" tab in the example doesn't show the function call. But you can easily see it using the network tools in your browser's debugged.
Allan
If I do exactly what you have done, the page doesn't work.
The only way in which the page works is to omit the $_GET['callback'] parameter.
With the network tool in the browser my response doesn't have the function call.
I use DataTables in a wordpress site not as a plugin but as a stand-alone script.
For some clients the page with the DataTable returns an error 403 and link to http://datatables.net/manual/tech-notes/7. This is why i try jsonp.
But this is more difficult than I expected... :(
Please link to the page so I can debug it. I presume you have used the
dataType: 'jsonp'
option in jQuery to make it request JSONP, but without a link to the page I can't say for sure what the issue is.Allan
Hi Allan,
today i realize my error. Terrible. Testing in a server but editing file in an other server.... sigh ^_^'
I knew that the problem had to be a strange thing.
I am extremely sorry I wasted your time. Thanks a lot for all!!