我是新來的jQuery/AJAX。 我試圖用jQuery/ajax/php發送單一輸入。用ajax/jquery/php發送單個輸入
但是,按提交什麼都沒發生後,哪裏是我的錯誤? 任何幫助非常感謝。
HTML:
<form action="submit.php">
<input id="number" name="number" type="text" />
<input id="submit" name="submit" type="submit" />
</form>
JQUERY/AJAX:
$(document).ready(function(e) {
$('input#submit').click(function() {
var number = $('input[name=number]');
var data = 'number=' + number.val();
$.ajax({
url: "submit.php",
type: "GET",
data: data,
cache: false,
success: function(html) {
if (html == 1) {
alert('wyslane');
}
else {
alert('error');
}
}
});
return false;
});
});
PHP:
<?php
$mailTo = '[email protected]';
$mailFrom = '[email protected]';
$subject = 'Call Back';
$number = ($_GET['number']) ? $_GET['number'] : $_POST['number'];
mail($mailTo, $subject, $number, "From: ".$mailFrom);
?>
當我測試你的實例時,Firebug告訴我PHP腳本是404 - 'GET submit.php?number = 23&_ = 1312128751227 404 Not Found 397ms' –