JSON成功/错误消息显示在本地服务器上,但不显示在godaddy服务器上



我的本地服务器上有PHP 5.4.45,Godaddy服务器上有PHP 5.4.45。

contact_p.php页面正确发送所有成功/错误消息,用于contact.phpform页面上输入的所有有效/无效数据。因此,我可以在contact.php页面上打印它们。

联系人查询已成功插入本地和godaddy服务器上的数据库表,但成功/错误消息仅显示在我的本地web服务器上,而不显示在godaddy服务器。

那么,这个奇怪问题的原因可能是什么呢?请告知,以便我可以在脚本和/或服务器上进行必要的更改。

contact.php

<form name="contactForm" id="contactForm" novalidate>
<div class="control-group form-group">
    .
    .
    other fields like Name, Mail, Phone, captcha etc
    .
    .
    <div id="success"></div>
    <!-- For success/fail messages -->
    <button type="submit" class="btn btn-primary">Send Message</button>
</div>
</form>

contact.js

$(function() {
$("#contactForm input,#contactForm textarea ,#contactForm select").jqBootstrapValidation({
    preventSubmit: true,
    submitSuccess: function($form, event) {
        event.preventDefault(); 
        var subject = $("select#subject").val();
        var name = $("input#name").val();
        var phone = $("input#phone").val();
        var email = $("input#email").val();
        var message = $("textarea#message").val();
        var secretcode = $("input#secretcode").val();
        $.ajax({
            url: "./user/contact_p.php",
            type: "POST",
            data: {
                subject: subject,
                name: name,
                phone: phone,
                email: email,
                message: message,
                secretcode: secretcode
            },
            cache: false,
            success: function(data) 
            {
                //alert(data);
                var $ResponseText_L=JSON.parse(data);
                if($ResponseText_L.status == 'SUC')
                {
                    // Success message
                    $('#successL').html("<div class='alert alert-success'>");
                    $('#successL > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                     $('#successL > .alert-success').append("<strong> " + $ResponseText_L.message + " </strong>");
                    $('#successL > .alert-success').append('</div>');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                }
                else if($ResponseText_L.status == 'ERR')
                {
                    // Fail message
                    $('#successL').html("<div class='alert alert-danger'>");
                    $('#successL > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#successL > .alert-danger').append("<strong> " + $ResponseText_L.message + " ");
                    $('#successL > .alert-danger').append('</div>');
                }
            },
        })
    },
    filter: function() {
        return $(this).is(":visible");
    },
});
$("a[data-toggle="tab"]").click(function(e) {
    e.preventDefault();
    $(this).tab("show");
});
});
/*When clicking on Full hide fail/success boxes */
$('#l_name').focus(function() {
    $('#successL').html('');
});

contact_p.php

$str_name = "";
if (isset($_POST["name"])) { $str_name = trim($_POST["name"]); }
$str_email = "";
if (isset($_POST["email"])) { $str_email = trim($_POST["email"]); }
$str_phone = "";
if (isset($_POST["phone"])) { $str_phone = trim($_POST["phone"]); }
$str_message = "";
if (isset($_POST["message"])) { $str_message = trim($_POST["message"]); }
$str_subject = "";
if (isset($_POST["subject"])) { $str_subject = trim($_POST["subject"]); }
$str_secretcode = "";
if (isset($_POST["secretcode"])) { $str_secretcode = trim($_POST["secretcode"]); }
if( empty($str_name))
{
    $response['status']='ERR';
    $response['message']= "Please enter full name!";
    echo json_encode($response); 
    return;
}
if( empty($str_message))
{
    $response['status']='ERR';
    $response['message']= "Please enter message!";
    echo json_encode($response); 
    return;
}
if( empty($str_subject) )
{
    $response['status']='ERR';
    $response['message']= "Please select subject!";
    echo json_encode($response); 
    return ;
}
if( empty($str_secretcode) || $_SESSION['image_secret_code'] != $str_secretcode )
{
    $response['status']='ERR';
    $response['message']= "Invalid Secret Code!";
    echo json_encode($response);
    return;
}
$str_query_insert="INSERT INTO t_contact_inquiry(subjectpkid, fullname, emailid, phone, description)";
$str_query_insert.=" VALUES(".$str_subject.",'".$str_name."','".$str_email."','".$str_phone."','".$str_message."')";    
ExecuteQuery($str_query_insert);    

$response['status']='SUC';
$response['message']="Your contact inquiry has been submitted";
echo json_encode($response);
return;

您的代码看起来还不错。尽管看起来contact.js中的$form变量尚未定义。你能核实一下吗?

编辑:对不起,在我第一次回答之前,我没有仔细研究你的代码。我认为这个问题可能在你的if()声明中。尝试修剪$ResponseText_L.status以确保其中没有空格。尝试if($ResponseText_L.status.trim() == 'SUC') { /display success message/ } else if($ResponseText_L.status.trim() == 'ERR') { /display error message/ } 。希望这能有所帮助!

最新更新