簡體   English   中英

即使成功執行PHP腳本,也不會顯示成功消息

[英]Success message not displaying even after successful PHP script execution

我在這里有一個奇怪的問題。 對於在contact.php表單頁面上輸入的所有無效數據, contact_p.php頁面會向我正確發送所有錯誤消息。 因此,我可以將它們打印在頁面上的紅色框和文本中。

成功執行腳本后, contact_p.php頁面也會向我發送成功消息。 我可以使用alert(data)檢查成功狀態和消息 contact.js頁面上。

但是由於某種原因,它不會在綠色框和文本中顯示成功消息。 我的意思是根本不打印成功消息。

我試圖解決幾個小時的錯誤,但沒有成功。 請讓我知道我在導致該奇怪問題的頁面上做錯了什么。

contact.php

<form name="FormPRegister" id="FormPRegister" 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" tabindex="9">Send Message</button>
</div>

contact.js

success: function(data) 
{
//alert(data);
var $responseText=JSON.parse(data);
if($responseText.staus == 'SUC')
{
    // Success message
    $('#success').html("<div class='alert alert-success'>");
    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
    .append("</button>");
    $('#success > .alert-success').append("<strong> " + $responseText.message + " </strong>");
    $('#success > .alert-success').append('</div>');

    //clear all fields
    $('#FormPRegister').trigger("reset");
}

else if($responseText.status == 'ERR')
{
    // Fail message
    $('#success').html("<div class='alert alert-danger'>");
    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
    .append("</button>");
    $('#success > .alert-danger').append("<strong> " + $responseText.message + " ");
    $('#success > .alert-danger').append('</div>');
}
},

contact_p.php

if( Invalid data then do this )
{
    $response['status']='ERR';
    $response['message']= "Invalid Secrete Code!";
    echo json_encode($response);
    return;
}

if( Valid data then do this )
{
    $response['status']='SUC';
    $response['message']= "Inquiry submitted successfully";
    echo json_encode($response);
    return;
}

我認為這是由於誤輸入。 您的JS代碼中有

if($responseText.staus == 'SUC')

代替

if($responseText.status == 'SUC')

您可以更正並重試嗎? 您沒有像Firebug這樣的JS調試器嗎?

編輯:不要忘記在重試之前重新加載緩存:例如在Firefox上使用ctrl + shift + R。

您在這里拼錯狀態:

if($responseText.staus == 'SUC')

它應該是 :

if($responseText.status == 'SUC')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM