Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jqueryajax从服务器端打印客户端页面中的成功消息_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 如何使用jqueryajax从服务器端打印客户端页面中的成功消息

Javascript 如何使用jqueryajax从服务器端打印客户端页面中的成功消息,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我使用jQueryAjax发布数据并相应地显示成功消息。 代码如下: Javascript HTML PHP服务器端 现在一切正常,但我无法将成功消息从服务器端发送到客户端。如何获取客户端页面中显示的成功消息。在客户端javascript中,当我在警报框中打印数据时,我看到一个空框。如何将数据变量从服务器端传递到客户端。试试看 echo "<script>$('#id or .class').html('error or success message here ');</

我使用jQueryAjax发布数据并相应地显示成功消息。 代码如下:

Javascript

HTML

PHP服务器端

现在一切正常,但我无法将成功消息从服务器端发送到客户端。如何获取客户端页面中显示的成功消息。在客户端javascript中,当我在警报框中打印数据时,我看到一个空框。如何将数据变量从服务器端传递到客户端。

试试看

echo "<script>$('#id or .class').html('error or success message here ');</script>";

使用echo、print或类似方法创建的PHP的输出是传递给调用Javascript的数据

在PHP代码中,在变量$form_数据中创建一个emtpy数组,然后使用echo json_encode$form_数据输出这个空数组。客户端的结果将是一个空数组,这对我来说并不奇怪


一句话:在PHP中输出的所有内容最终都将作为Ajax调用的成功处理程序中的数据

@Abhishekkadadi它在表单之外显示您的完整Html文件。请尝试$stage.htmldata而不是$stage.textdata未显示任何内容您正在将其显示在右侧$stage.textdata;警报数据;如果data.success{//If fails If data.errors{//如果process.php$'中有任何错误,则返回。throw_error.fadeIn1000.htmldata.errors;//throw相关错误console.loginside failure;}}否则{console.loginside success;$'stage.fadeIn1000.append'+data.posted+'';console.loginside success2;}};违约事件//防止默认提交};};-这是打印出来的对不起,我没听清楚。我已经用$form_数据创建了一个数组。你建议我做什么当我尝试回显$form_数据时,我在日志中成功打印了$form_数据,这是您将代码中的$form_数据输出到控制台的唯一位置!就在您将$form_数据定义为空数组之后。此时,$form_数据将被输出为空。
<form class="contact-form" method="post">


                        <h4 style="padding-top:8px;">Your email address will not be published. Required fields are marked <font color="red">*</font></h4>
                            <label>Name<font color="red">*</font></label><br>
                            <input class="form-control" style="height:35px;width:230px;border-radius:4px;" required type="text" name="name" id="name"/><br>
                            <label>Phone<font color="red">*</font></label><br>


        <span>

            <input id="element_4_1" name="element_4_1" class="element text" size="3" maxlength="3" value=""  type="text"> -

        </span>
        <span>
            <input id="element_4_2" name="element_4_2" class="element text" size="4" maxlength="4" value="" type="text"> -

        </span>
        <span>
            <input id="element_4_3" name="element_4_3" class="element text" size="10" maxlength="10" value=""  type="text" required >

        </span>

<br><br>
                            <label>Email<font color="red">*</font></label><br>
                            <input id="email" class="form-control" style="height:35px;width:230px;border-radius:4px;" required type="email" name="text"/><br>
                            <label for="input4">Message</label>
                            <textarea name="contact_message" class="form-control" rows="4" id="input4"></textarea>
                            <p>&nbsp;</p>
                            <button type="submit" style="margin-left:65px;"class="btn btn-large btn-info" id="button">Submit</button>
</form>  
<?php

ini_set('display_errors','On');
 error_reporting(E_ALL);
$errors = array(); 
    $form_data = array(); 
header('Content-type: application/json');
    echo json_encode($form_data);

$name=$_POST['name'];
$phone=chop($_POST['element_4_1']);
$phone.=chop($_POST['element_4_2']);
$phone.=chop($_POST['element_4_3']);
$email=chop($_POST['email']);
$message1=chop($_POST['input4']);

if ($name && $phone && $email) { 

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: sales@test.com \n";
$recipient= "test@test.in";



$subject="Online Enquiry   ";


$message="\nName                   : $name\n";

 $message.="\nPhone                  : $phone\n";

 $message.="\nEmail ID               : $email\n";

 $message.="\nMessage                : $message1\n";


 //send auto-reply
$subject_reply="Thank you for contacting us";
$message_reply="Thank you for contacting us. We will get back to you shortly.";
//mail($email, $subject_reply, $message_reply, $headers);



 //Send Mail
//===========
if(isset($recipient, $subject, $message, $headers)) {
error_log($message);
    $form_data['status'] = 'success';
error_log($form_data['status']);

} else {
    $form_data['status'] = 'error';
error_log($form_data['status']);

} 
}

?>
echo "<script>$('#id or .class').html('error or success message here ');</script>";