按照以下线程的示例和答案后
我已经构建了一个类似的测试表单,以便在提交时学习ajax请求。你的猜测是正确的,它对我没有用(没有警报弹出)。
我的testajax.php格式为:
我的test.js:
// this is the id of the form
$("#idForm").submit(function(e) {
var url = "(myurl)/testajaxinput.php"; // the script where you handle the form input.
e.preventDefault(); // avoid to execute the actual submit of the form.
警报(" BLA&#34); //无效
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
});
我应该处理输入的testajaxinput.php:
if (isset($_POST['feedbacksent'])){
echo "
".WORKS."
";}