我正在尝试通过本地应用程序中的实时服务器处理我的表单,而无需离开页面。下面是我用于表单、JQuery 和 PHP 的代码,但是当我发送它时,页面变为空白并将字符串放在 URL 栏中。请给我一些关于我的代码的帮助。我缩短了表格以使其更易于阅读,我还有很多其他领域。我是否需要将它们全部列在 javascript 中?
表单上的 HTML
<form action="http://mobile.koolantkoolers.com/mailer.php" method="get">
<div data-role="fieldcontain">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="" />
</div>
<div data-role="fieldcontain">
<label for="email">Email:</label>
<input type="email" name="email" id="email" value="" />
</div>
<div data-role="fieldcontain">
<label for="company">Company:</label>
<textarea cols="40" rows="8" name="company" id="company"></textarea>
</div>
<input type="button" onclick="submit()" value="submit" data-icon="star" data-theme="b" />
</div>
</form>
JavaScript:
$.post('http://mobile.koolantkoolers.com/mailer.php', {
// These are the names of the form values
Name: $('name').val(),
Email: $('email').val(),
Company: $('company').val()
// HTML function
}, function (html) {
// Place the HTML in a astring
var response=html;
// PHP was done and email sent
if (response=="success") {
alert("Message sent!");
} else {
// Error postback
alert("Sorry please fill all fields!");
return false;
}
});
然后是 PHP
<?php
// VARS
$Name=$_GET["name"];
$Email=$_GET["email"];
$Company=$_GET["company"];
$Headers = "From:" . $Email;
//VALIDATION
if(
$Name=="" ||
$Email=="" ||
$Company==""
) {
echo "Error";
} else {
mail("nnorman@dimplexthermal.com","mobile app message",$MessageText, $Headers);
echo "Success";
}
?>