目前我遇到了PHP / JSON的奇怪问题 直到昨天一切正常,没有改变编码。
让我解释整个情况。 我创建了一个订单处理系统,其中JSON用于获取信息并立即更新显示。 因此,其中一项功能是,如果找不到客户帐户,则搜索客户,创建新客户并立即使用该订单。
直到昨天这没有任何问题,如果没有找到客户帐户,则打开另一个屏幕并填写信息,并保存该帐户。
它使用JSON检查客户帐户是否存在。 然后用户返回主屏幕,帐号#已经填满,按Enter键填写姓名,地址,电话等(JSON也用于此)。
现在JSON没有找到信息,即使我正在检查数据库并保存了客户帐户。我直接打开JSON文件,以便在完成数据库更新时查看是否存在任何问题,但它显示为null。
当我刷新此页面时,它会找到相应的信息。
以下是用于编码JSON
的代码$stud_id = $_GET["id"];
$qr = "SELECT * FROM customers WHERE account = '$stud_id';";
$res= mysql_query($qr);
$row = mysql_fetch_array($res);
$stud_arr["customer_name"] = $row["name"];
$stud_arr["customer_address"] = $row["address"];
$stud_arr["customer_city"] = $row["city"];
$stud_arr["customer_state"] = $row["state"];
$stud_arr["customer_zipcode"] = $row["zipcode"];
$stud_arr["customer_phone"] = $row["phone"];
$stud_arr["customer_email"] = $row["email"];
$stud_arr["terms"] = $row["terms"];
header('Content-type: application/json;');
echo json_encode($stud_arr);
这是使用此代码的函数:
var id_val = m;
var url = "json.php?id=" + id_val + "&act=sales";
$("#customer_account").attr("disabled", "disabled");
$("#ajaxLoader").show();
$.getJSON(url, function(json) {
$.each(json, function(k, v) {
document.getElementById(k).value = v;
});
$("#ajaxLoader").hide();
if (isObjectEmpty(json)) {
alert("No customer found, please enter the customer account, or search for customer")
var answer = confirm("Do you want to create new account?", "yes", "no");
document.getElementById('customer_account').disabled = false;
document.getElementById('customer_account').focus();
if (answer == true) {
window.open('addNewCustomer.php?account=' + document.getElementById('customer_account').value).focus();
}
} else {
var url4 = "getAllShipTo.php?id=" + document.getElementById('customer_account').value;
var counterTemp = 1;
document.getElementById('ship_to').options[0] = new Option("Select Ship To", '');
$.getJSON(url4, function(json) {
$.each(json, function(k, v) {
document.getElementById('ship_to').options[counterTemp] = new Option(v, k);
document.getElementById('ship_to').options[counterTemp].id = counterTemp;
counterTemp++;
});
});
document.getElementById('customer_account').disabled = true;
document.getElementById('searchCustomer1').onclick = "";
document.getElementById('division').focus();
}
});

所以当我第一次打开订单输入屏幕时,会触发
window.open('addNewCustomer.php?account=' + document.getElementById('customer_account').value).focus();
然后,当输入客户帐户,并且我知道它已保存时,再次触发该帐户
window.open('addNewCustomer.php?account=' + document.getElementById('customer_account').value).focus();
但是如果我在地址栏中打开带有必要信息的json.php,首先它显示为null但是它显示正确的值,请参阅下面的内容。
{"customer_name":"null","customer_address":"null","customer_city":"null","customer_state":"null","customer_zipcode":"null","customer_phone":"null","customer_email":"null","terms":"null"}
刷新后:
{"customer_name":"te","customer_address":"te","customer_city":"te","customer_state":"te","customer_zipcode":"te","customer_phone":"te","customer_email":"","terms":"COD"}
所以我真的不知道发生了什么,以及如何解决这个问题。
任何帮助我都会感激,谢谢。