weixin_33717298 2016-10-15 13:55 采纳率: 0%
浏览 168

如何在C CGI中使用JQueryAjax?

有人能向我解释一下如何在C CGI中使用JQueryAjax吗?

以及如何初始化标题?

这是我的js代码片段:

$.ajax({
    type: "post",
    url: "check_username.cgi", 
    data:  username,
    function(exists){
        if(exists) $("#username").after("<p>Username" + username + "is not available.</p>");
    }
});

下面是我的c代码中成功编译的代码片段:

printf("Content-type:text/html; charset=UTF-8

"); \\I am having problem with this line.
int size, exists;
int length = (int) atoi(getenv("CONTENT_LENGTH"));
char username[length], query[128] = "select username from users where username = ";

fgets(username, length, stdin);

MYSQL *conn = mysql_init(NULL);
mysql_real_connect(conn, server, user, password, database, 0, NULL, 0);

strcat(query, username);
strcat(query, ";");

exists = (int) mysql_num_rows((MYSQL_RES *)mysql_query(conn, query));
mysql_close(conn);

if(exists) return 1;
else return 0;

在浏览器中测试之后,我的控制台中返回了这个:https://i.stack.imgur.com/N6N7V.png

如果你只是想告诉我使用python还是Perl,请不要回答......

  • 写回答

2条回答 默认 最新

  • weixin_33725515 2016-10-16 02:25
    关注

    I know now the mistake. It is so simple. This line:

    function(exists){
        if(exists) $("#username").after("<p>Username" + username + "is not available.</p>");
    }
    

    should be:

    success: function(exists){
        if(exists) $("#username").after("<p>Username" + username + "is not available.</p>");
    }
    
    评论

报告相同问题?