ajax动态添加数据库 php,ajax php 实现写入数据库_PHP教程

首先需要一个带输入表格.

复制代码 代码如下:

Insert 知识点

知识点

答案

需要js来处理提交数据到服务器上以及从服务器获取提交后的返回数据. submit.js代码如:

复制代码 代码如下:

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

var xmlHttp;

function getValue(){

alert("getvaluel");

var question =document.insertForm.question.value;

// alert(question);

var answer = document.insertForm.answer.value;

// alert(answer);

submit(question,answer);

};

function submit(question,answer){

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)

{

alert ("Your browser does not support AJAX!");

return;

}

xmlHttp.onreadystatechange =function(){

if(xmlHttp.readyState ==4){

alert(xmlHttp.responseText);

}

};

var url = "insert1.php";

xmlHttp.open("post",url,true);

xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");

xmlHttp.send("question="+question+"&answer="+answer);

}

function GetXmlHttpObject()

{

var xmlHttp=null;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;

}

然后PHP处理界面,负责跟服务器交换数据

复制代码 代码如下:

http://www.bkjia.com/PHPjc/320528.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320528.htmlTechArticle首先需要一个带输入表格. 复制代码 代码如下: !-- To change this template, choose Tools | Templates and open the template in the editor. -- !DOCTYPE HTML PUBLIC "-//...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值