"Internship" 2014-08-17 small error in JSON format spend 2 hours debugging

Source: Internet
Author: User

Symptom: The callback for $.get () or $.getjson () was not called when JQuery was developed, but was determined in Firebug to request the resource.

Cause: There was an error in the JSON format returned, "name": JSON, because this does not result in double quotation marks.

Elimination Process:
1. Check the HTTP header of the server and make sure Conten-type:application/json is not wrong.
2, the callback function is not executed, think of replacing the old available jquery and boostrap version, the result is not a version problem.
3, modify the callback function, no matter how can not execute.
4, compared with other correct JSON HTTP header, but no matter whether or not join Content-length.
5, modify the JSON into {error:0}, successfully, gradually contrast and incrementally debug JSON, found the problem. Fixed, successful.

The relevant code is as follows

Txproj_server.c

    /* Table */    Mysql_row *row = (mysql_row*) mysql_fetch_row (result);    while (row) {                                        /* Read lines *        /snprintf (line, MAXLINE,                //\ "%s\":%s, here is malformed, debug 2 hours!) The callback function for $.get[json] () has not been run.                "{\" id\ ":%s, \"%s\ ": \"%s\ ", \" amount\ ":%s, \" refund\ ":%s, \" create_time\ ": \"%s\ ", \" Status\ ":%s}",                (const char*) row[0], other, (const char*) row[1],                (const char*) row[2], (const char*) row[3], (const char*) row[4], ( Const char*) row[5]);        if (line) >= left)/                 * buffer is full */break strlen            ;        Strncat (data, line, left);        Left-= strlen (line);        Strncat (data, ",", 1);        row = (mysql_row*) mysql_fetch_row (result);    }




Txproj_list.cpp

        if (type!= "&& name!=" "&& token!=" "&& id!=" ") {        //if (type==" "| | name==" "| | token==" "| | id== "") {            string cmd = "list|" + type + ' | ' + id + ' | ' + token;            Send_reci (Cmd.c_str (), Cmd.size () +10, BUF_RECV, MAXLINE);            There are no lengths of            cout << "content-length:" << strlen (BUF_RECV) +32 << "\ r \ n";            cout << "Content-type:application/json" << "\r\n\r\n";            The format must be JSON correct, as $.get[json] callback function does not execute, big pits!!!            cout << buf_recv << "\ r \ n";            cout << "{\" error\ ": 0}" << "\ r \ n";            cout << "{\" error\ ": 0,\" type\ ": 2, \" len\ ": 0, \" data\ ": []}" << "\ r \ n";            cout << "{\" error\ ": 0,\" type\ ": 2, \" len\ ": 0, \" data\ ": [{\" test\ ": 1}]}" << "\ r \ n";        } else {


Txproj_buyer.html

$.get ("/cgi-bin/txproj_list", function (data) {        console.log (data);        });



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.