Coder Social home page Coder Social logo

xiaoshzx / ajax_cgi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ikaros-521/ajax_cgi

0.0 0.0 0.0 42 KB

ajax+cgi实现 html把数据通过ajax发给后台CGI,CGI程序将数据发回html并给对应控件赋值

Home Page: https://blog.csdn.net/Ikaros_521/article/details/103383981

C 93.77% HTML 6.23%

ajax_cgi's Introduction

相关说明

操作系统:CentOS7

Web服务器:BOA

语言:HTML+JS+C

演示了网页如何把数据通过AJAX发给后台CGI和后台CGI如何把数据返回到网页的指定控件显示

源码参考:AJAX_CGI

BOA的搭建参考:Linux下嵌入式Web服务器BOA和CGI编程开发

小案例实战参考:嵌入式web服务器BOA+CGI+HTML+MySQL项目实战——Linux

源码下载:GitHub码云

效果展示

ajaxtest1.html

在这里插入图片描述 实现效果:在对应输入框内输入内容调用对应函数,非空,就显示cgi程序返回的内容

	if(strstr(lenstr,"txtIDA")!=NULL)
	{
	    printf("[email protected]\n\n");
	}
	if(strstr(lenstr,"txtIDB")!=NULL)
	{
	    printf("Liuyixu\n\n");
	}

然后给对应控件进行赋值

document.getElementById("txtIDB").innerHTML=xmlhttp.responseText;

ajaxtest3.html

在这里插入图片描述 点击按钮

<input type="submit" value="get_info" onclick="get_info()" />

实现获取cgi发送回来的json字符串

	if(strstr(lenstr,"get_info") != NULL)
	{
	    printf("{\"A\":\"%s\",\"B\":\"%s\"}",ip,prot);
	}

转json对象,给对应控件赋值的效果

//将接收到的字符串存入jsonstr
var jsonstr = xmlhttp.responseText;
alert("json:"+jsonstr);
// 将jsonstr转换为json对象 json
var json = JSON.parse(jsonstr);
    if(json[name1]){
        var value = json[name1];
        // 直接给id为name1的控件赋值
        document.getElementById(name1).innerHTML = value;
    }
    if(json[name2]){
        var value = json[name2];
        document.getElementById(name2).innerHTML = value;
    }

ajax_cgi's People

Contributors

ikaros-521 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.