weixin_33726313 2014-08-26 23:42 采纳率: 0%
浏览 43

jQuery AJAX“未找到”错误

hello Whenever I click on the button that says "Get External Content" I get a javascript alert that says "Not Found" (this is the error's status text).

Why can it not find the text file I am trying to load via ajax?

This is my folder hierarchy:

--public_html
  --app
    --ajaxTestHome.php
    --ajaxTestText.txt

And this is the file I am trying to load (via ajax) the text file into.

//ajaxTestHome.php
    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("#ajax").click(function(){
        $.ajax(
            {
                url:"/app/ajaxTestText.txt", 
                success:function(result){
                    $("#div1").html(result);
                }, 
                error: function(abc) {
                    alert(abc.statusText);
                }, 
                cache: false
            }
        );
      });
    });
    </script>
    </head>
    <body>

    <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

    <button id="ajax">Get External Content</button>
    </body>
    </html>

EDIT: I had a typo in the question. the file is called "ajaxTestText.txt" not "ajaxTestTest.txt"

  • 写回答

3条回答 默认 最新

  • weixin_33695450 2014-08-26 23:45
    关注

    You shouldn't need the /app/ in the url.

    Also your file is called ajaxTestTest.txt and the url you are calling is ajaxTestText.txt they have different names

    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制