Resolves an issue where the AJAX request returned JSON could not resolve the "\" character

Source: Internet
Author: User

Reason: Get ID information, involving picture path, there is "\" character, resulting in JSON parsing error

Workaround: Change the return type from "JSON" to "text", when the returned data type becomes a string, replacing the string "\" with "/", there is no problem with JSON format error,

Then call Json.parse to parse into JSON format

$.ajax ({type:"GET",//How to submitURL: "Http://127.0.0.1:24010/ZKIDROnline/info",//PathData: {},//data, which is used in JSON format for transmissionDataType: ' JSON ', Success:function(data) {if(Data.ret = = 0{$.ajax ({type:"GET",//How to submitDataType: ' Text ', URL:"Http://127.0.0.1:24010/ZKIDROnline/ScanReadIdCardInfo?",//PathData: {' Op-dev ': 1, ' Cmd-url ': 4, ' common ': 1, ' Random ': 150},//data, which is used in JSON format for transmissionSuccess:function(data) {//The return data is processed accordingly according to the result                            data = Data.replace (/\\/g, "/");                                var result = null;                            result = Json.parse (data); if(Result.ret = = 0) { console.log(                                "Get ID Data"); }Else{ Console.log("Prompt", "ID data acquisition failed")                            }                        }                    }); Console.log ("Get Device Data"); } Else{Console.log ("Device Data not available"); }            }        });

Resolves an issue where the AJAX request returned JSON could not resolve the "\" character

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.