weixin_33709590 2015-03-23 00:00 采纳率: 0%
浏览 11

Ajax不会调用PHP文件

I have a Ajax function which should call search-engine.php but nothing happen.
Here my code:

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;
?>

And my input is inside a form tag with method post. If is important.

  • 写回答

2条回答 默认 最新

  • weixin_33711647 2015-03-23 00:09
    关注

    Your Javascript is all messed up. This is how it ought to look (compare and contrast with your code). And read the documentation!

     $.ajax('search-engine.php', {
          type: 'POST',
          data: { userInput:searchInput }
     }).done(function () {
          alert('works');
     }).fail(function () {
          alert('something went wrong');
     });
    

    And in the PHP you are using ( and ). You have to use the [ and ] characters. If you are not getting any errors then you should turn on errors!

    <?php
    $userInput = $_POST["userInput"];
    echo $userInput;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 关于远程桌面的鼠标位置转换
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?
  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!