weixin_33688840 2015-03-27 15:38 采纳率: 0%
浏览 21

带引导程序的AJAX请求

So I have this little script that fetches word definition from database. It's working fine. But as soon as I try to replace the default html input and button with Bootstrap stuffs by including Bootstrap CDN link in the header, it no longer works. There is no error, but the script simply won't fetch the result.

I have tried with different CDN link and everything I could with my limited jQuery knowledge. But I stuck. Below is my script. I have not included PHP script that responses JSON to jQuery AJAX script because it works fine too.

How can I fix my script so that I get it working? Right now, even simply inserting CDN link in the header make the script stop working.

$('document').ready(function(){
  $('#word-submit').on('click', function(){
    var word = $('#word').val();
    if ($.trim(word) != ''){
      $.post('ajax/name.php', {word: word}, function(data){
        var obj = jQuery.parseJSON(data);
        console.log(obj);
      });
    };          
  });
});
<html>
  <head>
    <title>Welcome</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="style.css">

  </head>
  <body>
    <div id="container">
      <form autocomplete="off" class="form-inline">
        <input type="text" id="word" >
        <input type="button" id="word-submit" value="Tam" class="sr-only" >
      </form>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
      <script src="js/global.js" charset="UTF-8"></script>

   </body>
</html>

</div>
  • 写回答

1条回答 默认 最新

  • Memor.の 2015-03-27 15:43
    关注

    You can't load an entire page like that using Ajax. You should only be loading the information contained in the body. If you have additional css / javascript files then you should append them to the page once you've loaded the content from Ajax.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog