JS Request Error: unexpected token T in JSON at position 0

Source: Internet
Author: User
Tags server port

<?php/* Recently done an AJAX validate form validation submitted code, when the AJAX submission JS request error: unexpected token T in the JSON at position 0 Description: This is a request, the parameters of the local newspaper this is the wrong, Excuse me, why? Best of all. Solution 1: To see the JSON format requirements, the Json.parse () method for JSON string requirements very strict solution 2:http://www.bejson.com/use this URL to test the JSON format is not wrong, line, Single quotation mark what will cause an error, the format requirements are very strict the following results in an error: the non-numeric key value in the JSON string does not have a tab in the double quotation mark JSON, which looks like a space, but is because its existence check does not pass. get rid of it. The editor has a BOM header that also causes Solution 3: A json.parse is used somewhere, but the passed-in parameter is not a qualified JSON string. The above describes the "(JavaScript) JS request error: unexpected token T in the JSON at position 0" problem answer, I hope to have the need to help users. *//***JS Ajax Send Code */$.validator.setdefaults ({submithandler:function () {///alert ("Commit event!");       return false;        var query=new Object ();        query.user_name=$ (' #user_name '). Val ();        query.sex=$ (' #sex '). Val ();        query.country=$ (' #country '). Val ();        query.email=$ (' #email '). Val ();        query.mobile=$ (' #mobile '). Val ();        query.weixin=$ (' #weixin '). Val ();        query.address=$ (' #address '). Val ();        query.messages=$ (' #messages '). Val ();        var url= "/controller/apply.php";          $.ajax ({  Url:url, type: "POST", Data:query, DataType: "JSON", Success:function (res) {                    if (res.status==1) {alert (res.msg);                Window.location.replace ("http://www.fxbob.com/a/zhongwen/hezuohuoban/20170620/21.html");                }else{alert (res.msg); }}, Error:function (XMLHttpRequest, Textstatus, Errorthrown) {Console.log (xmlhttpreques             T); Console.log (Errorthrown); alert (xmlhttprequest.status); alert (xmlhttprequest.readystate);        alert (textstatus);},complete:function (XMLHttpRequest, textstatus) {this;//The options parameter passed when calling this Ajax request}});    return false; }});/***php's Ajax receive code apply.php as follows: */<?php//Header ("content-type:text/html; Charset=utf-8 ");d efine (' Dedemob ', ' Y '); require_once (DirName (__file__)." /.. /include/common.inc.php ");//Load Message Class require_once (DirName (__file__)." /.. /include/smtp.class.php "), if ($_post) {$datA=$_post, $str =<<<eot

JS Request Error: unexpected token T in JSON at position 0

Related Article

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.