Ajax combined with Cgi__ajax

Source: Internet
Author: User

Found Ajax is really good dongdong: You can only pass the XML simple client want data.

Client Ajax Code:

<script language= "JavaScript" type= "Text/javascript" >
<!--

Initiates a XMLHTTP request to the server.
var http_request = null;
function GetData ()
{
Start initializing the XMLHttpRequest object
if (window. XMLHttpRequest)//mozilla Browser
{
Http_request = new XMLHttpRequest ();
if (http_request.overridemimetype) {//Set MIME category
Http_request.overridemimetype (' Text/xml ');
}
}
else if (window. ActiveXObject)//IE browser
{
Try
{
Http_request = new ActiveXObject ("Msxml2.xmlhttp");
}
catch (E)
{
Try
{
Http_request = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (e) {}
}
}

exception, creating object instance failed
if (!http_request)
{
Window.alert ("Cannot create XMLHttpRequest object instance.");
return false;
}

Http_request.onreadystatechange = ProcessResponse;

Determine how the request is sent
Http_request.open ("Get", ".. /cgi-bin/status.cgi ", true);
Http_request.send (NULL);
}

Functions that process return information
function ProcessResponse ()
{
if (http_request.readystate = = 4)//Judging object status
{
if (Http_request.status = 200)//information has been successfully returned to begin processing information
{
var result = Http_request.responsetext;
if (Result.indexof ("#")!=-1)
{
Show (result);
}
Else
{
}
}
else//page is not normal
{
Alert ("The page you are requesting has an exception.) ");
}
}
}

The CGI side can use the Cgic library (a good library, but main () in the library, the main () to a common interface is the best):

#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>

int Showinfo ();

int Cgimain ()
{
Cgiheadercontenttype ("text/html"); Not less

* Now show the form * *
fprintf (Cgiout, "1#2#3#", szName);


return 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.