我的代码有问题了。
在html文件中:
<form id='changeAccountForm' action='usermenu.php' method='post'>
Name:<input type="text" name="name"/>
Surname:<input type="text" name="surname"/>
Password:<input type="password" name="password"/>
Phone:<input type="text" name="phone"/>
Paid mail:<input type="text" name="paidMail"/>
Payment method:<input type="radio" name="paymentMethod" value="0"/>paypal
<input type="radio" name="paymentMethod" value="1"/>payza
<div id="changeAccountInformation" >change</div>
</form>
在Javascript文件中我使用Javascript和jQuery。我使用带有ajax的javascript和名为:
的函数function ajaxInit(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
return ajaxRequest;
}//end function ajaxInit
function updateUserDataWithAjax(){
var ajaxRequest = ajaxInit();
// Create a function that will receive data
// sent from the server and will update
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
// find all form elements and add the responseText to placeholder attribute
var childNodes = $("#changeAccountForm").children(),i,j=0;
var inputAjaxRequest = ajaxRequest.responseText;
//inputAjaxRequest = inputAjaxRequest.plit(",");//ERROR:
for(i=0; i<childNodes.length; i++)
if(childNodes[i]!= "input"){
childNodes[i].setAttribute("placeholder",inputAjaxRequest[j++]);
}
}
}
var namesArray = "userId,password,name,phone,";
namesArray+= "surname,paidMail,payMethod,";
namesArray+= "score";
namesArray = namesArray.split(',');
//gets all the childnodes and find these with attribute
var childNodes = $("#changeAccountForm").children(),values,names,i;
var queryString = '';
var first = true;
for(i=0; i<childNodes.length; i++)
for(j=0;j<namesArray.length;j++)
if(childNodes[i].getAttribute("name")==namesArray[j]){
values = childNodes[i].value;
names = childNodes[i].getAttribute("name");
if (first){
queryString += names+"="+values;
first = false;
}else
queryString += "&"+names+"="+values;
}
ajaxRequest.open("POST", "usermenu.php", true);
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", queryString .length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(queryString);
}
//and i call this function
$(document).ready( function(){
$("#changeAccountInformation").click(function(){
var user = updateUserDataWithAjax();
});
});
在php文件中: 当我使用该方法发布错误并打印未定义的索引:[键值名称] in。来自ajax的响应文本是一个名为html文件的数组。
include "userMenu.html";
isset($_POST['name']);
echo $_POST['name'];
任何信息都将不胜感激,谢谢。