The previous article said that in the Ajax callback to deal with the refresh of the iframe window, this article records the one encountered in the IFrame and the div window in the AJAX request 200 state when the callback problem is executed.
Let's take a look at the wording of the AJAX request (jquery is used here)
function Check_pass (UID) {$.ajax ({type:"GET", Url:siteurl, DataType:"JSON", data:{"C":"API", "m":"Checkpass", "UID": Uid}, success:function (data) {Console.log ("Here's the success callback ."); Console.log (data); }, Error:function (XMLHttpRequest, Textstatus, Errorthrown) {Console.log ("This is the error callback ."); //Status CodeConsole.log (xmlhttprequest.status); //error MessageConsole.log (Errorthrown); } });}
For most of us, the AJAX request returns a "Ten OK" status code, which means that the request succeeds and executes the success method, so let's do an experiment:
First we notice that this AJAX request specifies datatype as JSON, then we return different types of data in the interface to test the return results of the IFRAME and div;
1. Interface returns JSON data
Publicfunction Checkpass () {$uid= $ This->input->Get('UID'); $data= Array ('Checkcode'=1, 'reason'=NULL ); $ This->db->where('UID', $uid); $ This->db->update ('Mt_member_data', $data); $msg = Array (' msg ' = ' audit pass ', ' code ' = ' 1 ' )); echo Json_encode ($msg); Exit }
Perform AJAX request console printing in the iframe window (Network display status 200ok):
This is the success callback . " audit through ""1"}
Perform AJAX request console printing in modal window div (Network display status 200ok):
This is the success callback . " audit through ""1"}
Conclusion: Ajax in the IFrame and Div will go success callback when the interface returns a data type of JSON (which conforms to Ajax settings).
2. Interface returns NULL
Publicfunction Checkpass () {$uid= $ This->input->Get('UID'); $data= Array ('Checkcode'=1, 'reason'=NULL ); $ This->db->where('UID', $uid); $ This->db->update ('Mt_member_data', $data); }
Perform AJAX request console printing in the iframe window (Network display status 200ok):
This is the error callback . $ syntaxerror:unexpected end of JSON input at json.parse (<anonymous>) at M.parsejson ( Jquery.min.js:5) at Pb (jquery.min.js:5) at X (jquery.min.js: 5 ) at xmlhttprequest.b (jquery.min.js:5)
Perform AJAX request console printing in modal window div (Network display status 200ok):
This is the success callback . NULL
Conclusion: When the interface return data type is null (does not conform to Ajax settings), the AJAX error callback in the IFrame, modal window div in the Ajax is to go success callback.
3. Interface returns non-JSON data
Publicfunction Checkpass () {$uid= $ This->input->Get('UID'); $data= Array ('Checkcode'=1, 'reason'=NULL ); $ This->db->where('UID', $uid); $ This->db->update ('Mt_member_data', $data); Echo "Non-JSON data"; Exit; }
Perform AJAX request console printing in the iframe window (Network display status 200ok):
This is the error callback . $ in JSON @ position 0at json.parse (<anonymous>) at M.parsejson ( Jquery.min.js:5) at Pb (jquery.min.js:5) at X (jquery.min.js :5) at xmlhttprequest.b (jquery.min.js:5)
Perform AJAX request console printing in modal window div (Network display status 200ok):
This is the error callback . $ in JSON @ position 0at json.parse (<anonymous>) at Parsejson (VM1506 Jquery.min.js:2) at on (VM1506 jquery.min.js:2) at T (VM1506 Jquery.min.js:2) at XMLHTTPREQUEST.R (VM1506 jquery.min.js:2)
Conclusion: When the interface return data type is non-JSON data (does not conform to Ajax settings), the IFrame and modal window div in the Ajax is to go error callback, and report the wrong format of the data.
Therefore, it is worth noting that when the interface does not return data (that is, null), the callback function executed after the request succeeds for the Ajax requests originating in the IFrame and Div is different.
About callback issues that are performed when the AJAX request 200 state is in the IFrame and div windows