Why does javascript-Jqueryajaxjson not execute success?

Source: Internet
Author: User
{Code ...} now the error method is executed to view the information on the Internet. As the Jquery version increases, there are strict requirements on the json format. The returned information is similar to this format {success: true, id: 1, result: & quot; OK & quot;} is no longer applicable in high versions. You must change the format below to {& quot; su...
$. Ajax ({url: 'xxxx. com/index. php/Home/Shop/transCloseShop ', type: 'get', dataType: 'jsonp', timeout: 1000, cache: false, data: {robot: "123", usertype: "0", userid: "22", shopid: "4", transToCondition: 1,}, error: erryFunction, // error execution method success: succFunction // successful execution method}) function erryFunction (data) {console. log (data);} function succFunction () {alert ("22 ");}

The error method is executed.

View online information

As the Jquery version improves, there are strict requirements on the json format. The returned information similar to this format is {success: true, id: 1, result: "OK"} is no longer applicable in high versions. You must change the format to {"success": true, "id": "1"} to run the success callback normally.

But below is my strict json format.

Below is the json output by the server

[{"shop_id":"3","shop_name":"\u65b0\u4e16\u754c\u4e2d\u9910","shop_bossid":"22","shop_history_bossid":"-22","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460110593","shop_updatetime":"1460110593","opentime":"46\u592915\u5c0f\u65f645\u5206\u949f12\u79d2","historyboss":";13881119614;"},{"shop_id":"4","shop_name":"\u4e2d\u4e1c\u4e16\u754c","shop_bossid":"22","shop_history_bossid":"-18-15","shop_condition":"1","shop_isdelete":"0","shop_createtime":"1460111243","shop_updatetime":"1460111243","opentime":"46\u592915\u5c0f\u65f634\u5206\u949f22\u79d2","historyboss":";;;"},{"shop_id":"5","shop_name":"\u80af\u6253\u9e21","shop_bossid":"22","shop_history_bossid":"","shop_condition":"1","shop_isdelete":"0","shop_createtime":"1460116195","shop_updatetime":"1460116195","opentime":"46\u592914\u5c0f\u65f611\u5206\u949f51\u79d2","historyboss":""},{"shop_id":"6","shop_name":"\u54c8\u6839\u8fbe\u65af","shop_bossid":"22","shop_history_bossid":"-22-17","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460116659","shop_updatetime":"1460116659","opentime":"46\u592914\u5c0f\u65f64\u5206\u949f7\u79d2","historyboss":";13881119614;;"},{"shop_id":"12","shop_name":"\u5b9c\u5bbe\u71c3\u9762","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460378016","shop_updatetime":"1460378016","opentime":"43\u592913\u5c0f\u65f628\u5206\u949f10\u79d2","historyboss":""},{"shop_id":"13","shop_name":"\u78e8\u83dc\u5200","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460421729","shop_updatetime":"1460421729","opentime":"43\u59291\u5c0f\u65f619\u5206\u949f37\u79d2","historyboss":""},{"shop_id":"26","shop_name":"\u7f8a\u7ecd\u6b66","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1462841544","shop_updatetime":"1462841544","opentime":"15\u59291\u5c0f\u65f69\u5206\u949f22\u79d2","historyboss":""},{"shop_id":"27","shop_name":"\u4e1c\u62c9\u897f\u626f","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1462842809","shop_updatetime":"1462842809","opentime":"15\u59290\u5c0f\u65f648\u5206\u949f17\u79d2","historyboss":""},{"shop_id":"29","shop_name":"13123","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1462955116","shop_updatetime":"1462955116","opentime":"13\u592917\u5c0f\u65f636\u5206\u949f30\u79d2","historyboss":""},{"shop_id":"30","shop_name":"\u9999\u5929\u4e0b\u706b\u9505","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463276283","shop_updatetime":"1463276283","opentime":"10\u59290\u5c0f\u65f623\u5206\u949f43\u79d2","historyboss":""},{"shop_id":"31","shop_name":"\u9999\u5929\u4e0b\u706b\u9505","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463276286","shop_updatetime":"1463276286","opentime":"10\u59290\u5c0f\u65f623\u5206\u949f40\u79d2","historyboss":""},{"shop_id":"32","shop_name":"\u9999\u5929\u4e0b\u706b\u9505","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463276289","shop_updatetime":"1463276289","opentime":"10\u59290\u5c0f\u65f623\u5206\u949f37\u79d2","historyboss":""},{"shop_id":"33","shop_name":"\u8d85\u5e02\u5b9d","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546341","shop_updatetime":"1463546341","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f45\u79d2","historyboss":""},{"shop_id":"34","shop_name":"\u8d85\u5e02\u5b9d","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546342","shop_updatetime":"1463546342","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f44\u79d2","historyboss":""},{"shop_id":"37","shop_name":"\u8d85\u5e02\u5b9d","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546345","shop_updatetime":"1463546345","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f41\u79d2","historyboss":""},{"shop_id":"39","shop_name":"","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546346","shop_updatetime":"1463546346","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f40\u79d2","historyboss":""},{"shop_id":"40","shop_name":"","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546347","shop_updatetime":"1463546347","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f39\u79d2","historyboss":""}]

Reply content:
$. Ajax ({url: 'xxxx. com/index. php/Home/Shop/transCloseShop ', type: 'get', dataType: 'jsonp', timeout: 1000, cache: false, data: {robot: "123", usertype: "0", userid: "22", shopid: "4", transToCondition: 1,}, error: erryFunction, // error execution method success: succFunction // successful execution method}) function erryFunction (data) {console. log (data);} function succFunction () {alert ("22 ");}

The error method is executed.

View online information

As the Jquery version improves, there are strict requirements on the json format. The returned information similar to this format is {success: true, id: 1, result: "OK"} is no longer applicable in high versions. You must change the format to {"success": true, "id": "1"} to run the success callback normally.

But below is my strict json format.

Below is the json output by the server

[{"shop_id":"3","shop_name":"\u65b0\u4e16\u754c\u4e2d\u9910","shop_bossid":"22","shop_history_bossid":"-22","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460110593","shop_updatetime":"1460110593","opentime":"46\u592915\u5c0f\u65f645\u5206\u949f12\u79d2","historyboss":";13881119614;"},{"shop_id":"4","shop_name":"\u4e2d\u4e1c\u4e16\u754c","shop_bossid":"22","shop_history_bossid":"-18-15","shop_condition":"1","shop_isdelete":"0","shop_createtime":"1460111243","shop_updatetime":"1460111243","opentime":"46\u592915\u5c0f\u65f634\u5206\u949f22\u79d2","historyboss":";;;"},{"shop_id":"5","shop_name":"\u80af\u6253\u9e21","shop_bossid":"22","shop_history_bossid":"","shop_condition":"1","shop_isdelete":"0","shop_createtime":"1460116195","shop_updatetime":"1460116195","opentime":"46\u592914\u5c0f\u65f611\u5206\u949f51\u79d2","historyboss":""},{"shop_id":"6","shop_name":"\u54c8\u6839\u8fbe\u65af","shop_bossid":"22","shop_history_bossid":"-22-17","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460116659","shop_updatetime":"1460116659","opentime":"46\u592914\u5c0f\u65f64\u5206\u949f7\u79d2","historyboss":";13881119614;;"},{"shop_id":"12","shop_name":"\u5b9c\u5bbe\u71c3\u9762","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460378016","shop_updatetime":"1460378016","opentime":"43\u592913\u5c0f\u65f628\u5206\u949f10\u79d2","historyboss":""},{"shop_id":"13","shop_name":"\u78e8\u83dc\u5200","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1460421729","shop_updatetime":"1460421729","opentime":"43\u59291\u5c0f\u65f619\u5206\u949f37\u79d2","historyboss":""},{"shop_id":"26","shop_name":"\u7f8a\u7ecd\u6b66","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1462841544","shop_updatetime":"1462841544","opentime":"15\u59291\u5c0f\u65f69\u5206\u949f22\u79d2","historyboss":""},{"shop_id":"27","shop_name":"\u4e1c\u62c9\u897f\u626f","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1462842809","shop_updatetime":"1462842809","opentime":"15\u59290\u5c0f\u65f648\u5206\u949f17\u79d2","historyboss":""},{"shop_id":"29","shop_name":"13123","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1462955116","shop_updatetime":"1462955116","opentime":"13\u592917\u5c0f\u65f636\u5206\u949f30\u79d2","historyboss":""},{"shop_id":"30","shop_name":"\u9999\u5929\u4e0b\u706b\u9505","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463276283","shop_updatetime":"1463276283","opentime":"10\u59290\u5c0f\u65f623\u5206\u949f43\u79d2","historyboss":""},{"shop_id":"31","shop_name":"\u9999\u5929\u4e0b\u706b\u9505","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463276286","shop_updatetime":"1463276286","opentime":"10\u59290\u5c0f\u65f623\u5206\u949f40\u79d2","historyboss":""},{"shop_id":"32","shop_name":"\u9999\u5929\u4e0b\u706b\u9505","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463276289","shop_updatetime":"1463276289","opentime":"10\u59290\u5c0f\u65f623\u5206\u949f37\u79d2","historyboss":""},{"shop_id":"33","shop_name":"\u8d85\u5e02\u5b9d","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546341","shop_updatetime":"1463546341","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f45\u79d2","historyboss":""},{"shop_id":"34","shop_name":"\u8d85\u5e02\u5b9d","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546342","shop_updatetime":"1463546342","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f44\u79d2","historyboss":""},{"shop_id":"37","shop_name":"\u8d85\u5e02\u5b9d","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546345","shop_updatetime":"1463546345","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f41\u79d2","historyboss":""},{"shop_id":"39","shop_name":"","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546346","shop_updatetime":"1463546346","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f40\u79d2","historyboss":""},{"shop_id":"40","shop_name":"","shop_bossid":"22","shop_history_bossid":"","shop_condition":"0","shop_isdelete":"0","shop_createtime":"1463546347","shop_updatetime":"1463546347","opentime":"6\u592921\u5c0f\u65f622\u5206\u949f39\u79d2","historyboss":""}]

jsonpThe request has special requirements. Your code should be similar:

$. Ajax ({url: 'xxxx. com/index. php/Home/Shop/transCloseShop ', type: 'get', ype: 'jsonp', timeout: 1000, cache: false, jsonp: false, data: {robot: "123", usertype: "0", userid: "22", shopid: "4", transToCondition: 1,}, jsonpCallback: 'successcallback'}) function successCallback (data) {console. log ('success! ');}

Then the content returned by the server cannot be a purejsonIt must be an executable script.jsonpCallback, The content returned by the server should look like this:

successCallback([{"shop_id":"3","shop_name":"\u65b0\u4e16\u754c\u4e2d\u9910"...}]);

The problem lies here.dataType : 'jsonp'. I changed the typejsonCallsuccessMethod.
The data you return is just a commonjsonData.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.