[英]Ajax won't call PHP file
我有一个应该调用search-engine.php的Ajax函数,但没有任何反应。
这是我的代码:
阿贾克斯:
$.ajax(){
type: 'POST',
url: 'search-engine.php',
data: {userInput: searchInput},
success: function(){
alert('works');
},
error: function(){
alert('something went wrong');
}
}
PHP:
<?php
$userInput = $_POST("userInput");
echo $userInput;
?>
我的输入是在带有方法发布的表单标签中。 如果重要。
您的Javascript全部搞砸了。 这就是它的外观(与您的代码进行比较和对比)。 并阅读文档 !
$.ajax('search-engine.php', {
type: 'POST',
data: { userInput:searchInput }
}).done(function () {
alert('works');
}).fail(function () {
alert('something went wrong');
});
在PHP中,您正在使用(
和)
。 您必须使用[
和]
字符。 如果没有任何错误,则应打开错误!
<?php
$userInput = $_POST["userInput"];
echo $userInput;
您必须将config对象传递给ajax函数:
$.ajax({
type: 'POST',
url: 'search-engine.php',
data: {userInput: searchInput},
success: function(){
alert('works');
},
error: function(){
alert('something went wrong');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.