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

时间:2016-03-29 16:59:55

标签: php jquery json

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

contact_p.php 页面会针对 contact.php 表单页面上输入的所有有效/无效数据正确发送所有成功/错误消息。所以我可以在 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;

1 个答案:

答案 0 :(得分:0)

你的代码似乎很好。虽然看起来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/ } 。希望这有帮助!