来自PHP文件的JSON结果是代码,而不是文本
我在update_customer.PHP文件中有PHP代码,用于保存客户信息来自PHP文件的JSON结果是代码,而不是文本,php,jquery,json,Php,Jquery,Json,我在update_customer.PHP文件中有PHP代码,用于保存客户信息 <?php date_default_timezone_set('Asia/Ho_Chi_Minh'); $response = array( 'status' => 0, 'message' => '', 'typeinsurance' => '', 'thoigianmua' => 0 ); if (empty($_GET) && !empty($_POS
<?php
date_default_timezone_set('Asia/Ho_Chi_Minh');
$response = array( 'status' => 0, 'message' => '', 'typeinsurance' => '', 'thoigianmua' => 0 );
if (empty($_GET) && !empty($_POST) && count($_POST) == 7 && isset($_POST['fullname']) && isset($_POST['email']) &&
isset($_POST['address']) && isset($_POST['phone']) && isset($_POST['cost']) && isset($_POST['typeinsurance']) &&
isset($_POST['typepay']))
{
require_once ('./../include/database.php');
$database = new Database();
$time = time();
$_POST['thoigianmua'] = $time;
if ($database->insert('customer', $_POST)){
$response['status'] = 1;
$response['typeinsurance'] = $_POST['typeinsurance'];
$response['thoigianmua'] = $time;
}
}
echo json_encode($response);
您的php代码肯定有错误,这就是为什么它会以您意想不到的方式返回数据
错误的部分是
您将php代码作为字符串提供
你必须检查你的php文件向我们展示生成此输出的php代码。你能展示一个你期望的JSON示例以及应该生成它的字段的输入吗?这是我的php代码$response['status']=1$回复['typeinsurance']=$_POST['typeinsurance'];$response['thoigianmua']=$time
据我所知,您似乎正在通过post字段typeinsurance
发送实际字符串
,但我发现很难将您的代码与输出关联起来-您可以发布更多实际生成响应的代码和发送请求的代码吗?我想显示JSON对象{状态:1,消息:“,类型保险:“xehaibanh”,thoigianmua:1440642246
这是我的代码PHP我没有投反对票,但可能是因为你的答案对他解决问题没有任何帮助。@Ken先生不要试图将代码放在注释中。编辑问题。我将代码放在问题中,并有代码通知,但没有allowed@MrKen问题中已经有代码,可以添加更多
Object {status: 1, message: "", typeinsurance: "<?php echo $_POST['typeinsurance']; ?>", thoigianmua: 1440642246}