简体   繁体   English

PHP无法在使用Ajax时回显表单输入

[英]PHP not able to echo form input while using Ajax

My PHP file echo's the statement but cannot echo the actual value given by user. 我的PHP文件回显了该语句,但无法回显用户提供的实际值。

I am using ajax and on the left hand side there is a form which asks for email id. 我正在使用ajax,在左侧有一个要求提供电子邮件ID的表格。 When the email id is entered and form submitted, the results need to show on the right hand side. 输入电子邮件ID并提交表单后,结果需要显示在右侧。

On submitting the form though, the php is able to echo the statement "You have entered :" but cannot echo the actual email id entered. 在提交表单时,php能够回显“您已输入:”语句,但无法回显输入的实际电子邮件ID。

Pls help 请帮助

This is the form:- 这是表格:-

<form action="javascript:ajaxpage('files/search2.php', 'columnTwo')" method="POST">
                        Email :<input type="text" name="email" value=""/>
                        <input type="submit" value="Submit">`
</form>

This is the PHP file:- 这是PHP文件:-

<?php
$email = $_POST['email'];
echo "The Email ID is :";
echo $email;
?>
<html>
<body>
<h1>Hello World</h1>
</body>
</html>

Only the message "The Email ID is :" is displayed 仅显示消息“电子邮件ID为:”

$email not displayed $ email不显示

First : use eventHandlers, not action="javascript:blah()"; 首先:使用eventHandlers,而不要使用action="javascript:blah()"; Second : in your javascript ajax function get the values form your inputs and send them to the php file using post method.You can make your own ajax, but there are also libraries for that, like prototype.js or jquery that are easy to use. 其次:在您的javascript ajax函数中,从输入中获取值并使用post方法将其发送到php文件中。您可以创建自己的ajax,但也有用于该类的库,例如prototype.js或jquery易于使用。 Read into it a little, it's quite easy, and return here if you have problems implementing it. 仔细阅读它,这很容易,如果在实现它时遇到问题,请返回此处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM