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); });