"dataSrc" returns unaltered JSON result, but it doesn't work.
"dataSrc" returns unaltered JSON result, but it doesn't work.
Hello,
I have a web-application, it uses the ajax parameter for requesting and inserting JSON data into the table.
However at the top of the requested .php file it is checked whether the user is logged in, if not the script encodes a different array: { logged: "false" } .
Normally there isn't an issue however when the user has multiple tabs open and the session is destroyed on just one of them the other tabs break (because of logged in check).
I wanted to catch the result { logged: "false" } and handle it accordingly. For this I want to use the dataSrc property.
I succeeded in this endeavor, however the function doen't return the result properly anymore.
The important piece of code:
"ajax": {
"url": "php/get_issues.php" + "?id=" + id + "&customer_id=" + customerid,
"dataSrc": function ( json ) {
if(typeof json['logged'] != "undefined") {
if (json['logged'] == 'false') {
location.replace('php/logout.php');
}
}
return json;
}
},
The .php script returns data like this: http://i66.tinypic.com/a3zi1x.png
This question has an accepted answers - jump to answer
Answers
You probably need to use
return json.data;. If you useajax.dataSrcas a function it expects you to return the data array, not the original object.Allan
json.dataisundefined.JSON.stringify(json)returns the json string.Perhaps you could let me know what the structure of
jsonis when valid data is returned then please? Also a link to the page, as requested in the forum rules, would be useful to let me debug and address the issue.Allan
The
.phpscript returns data like this: http://i66.tinypic.com/a3zi1x.png The script contains the properapplication/jsonheader.I am unable to post an proper working link because the web page isn't online and because it contains corporate data. I will try and get some more info that might be relevant.
Thanks for supporting me.
Edit:
If i completely comment out the
dataSrcproperty, it works like a charm.So just use
return json.aaDatain that case :-). As I said, return the data array.Allan
Thanks alot! I never though
.datawas referencing to the first array item (which in this case is also an array).Again, thanks a lot!