我有
enter code here
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
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 is too old to run me!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
$.post('userfind.php', function(data) {
document.getElementById("myTable").style.display = "block";
var x=document.getElementById("myTable");
for (var i = 0; i < data.length; i++) {
var row=x.insertRow(-1);
var cell1=row.insertCell(-1);
var cell2=row.insertCell(-1);
...
...
并在 php
enter code here
<?php
session_start();
$username = "XXXXXXXX";
$password = "XXXXXXXX";
$database = "XXXXXXXX";
$link = mysql_connect("localhost", "$username", "$password");
if(!$link) {echo("Failed to establish connection to mysql server");
exit();}
$status = mysql_select_db($database);
$oId = mysql_real_escape_string($_POST["order_IDsearch"]);
if (isset($order_IDsearch)){
$result = mysql_query ("SELECT * FROM personal_info WHERE order_id= '".$oId."' ");
$myjsons = array();
while($row = mysql_fetch_assoc($result)){
$myjsons[] = $row;
}
echo json_encode($myjsons);
}
?>
如果我删除 SQL 条件、matrk if 并标记 $_post,javascript 将显示表格
如果我离开 php 如上所示,它不会显示表格,
请问php页面有什么问题
这是整个 javascript ajax 函数,
enter code here
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
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 is too old to run me!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
$.post('userfind.php', {orderId:"order_IDsearch"}, function(data) {
var obj = $("#myTable").show();
var x = obj.get(0);
for (var i = 0; i < data.length; i++) {
var row=x.insertRow(-1);
var cell1=row.insertCell(-1);
...
...
cell1.innerHTML = "<b><input name='edit' type='button' onClick='editRow(this)' value='Edit' /> <input name='del' type='button' onClick='delRow(this)' value='Del' /></b>";
cell2.innerHTML = data[i].user_id;
cell3.innerHTML = data[i].first_name ;
....
....
}},'json');}
}
ajaxRequest.open("POST", "userfind.php", true);
ajaxRequest.send(null);
}
太困惑了,请帮我修改代码,我应该重新编写代码吗?可以修改此代码吗?