我有一个 jquery 移动网站,表单提交 ajax Post 请求 - 回调总是错误而不成功 - 请查看 url: property 我认为有问题:
HTML
<div data-role="content">
<form id="callAjaxForm">
<div data-role="fieldcontain">
<label for="firstName">First Name</label>
<input type="text" name="firstName" id="firstName" value="" />
<label for="lastName">Last Name</label>
<input type="text" name="lastName" id="lastName" value="" />
<h3 id="notification"></h3>
<button data-theme="b" id="submit" type="submit">Submit</button>
</div>
</form>
</div>
JS
$(document).ready(function() {
$("#submit").click(function(){
var formData = $("#callAjaxForm").serialize();
$.ajax({
type: "POST",
url: "http://localhost/wodowod/ajaxtest.php",
cache: false,
data: formData,
success: onSuccess,
error: onError
});
return false;
});
});
PHP
if(isset($_POST['firstName']) && isset($_POST['lastName'])){
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
echo("First Name: " . $firstName . " Last Name: " . $lastName);
}
else {
echo "Invalid Request";
}