0

I am attempting to load chat messages with a javascript jQuery function using AJAX. I am new to jQuery and this is my first time using AJAX along with it. I call the function from my html with a script tag. My HTML source appears to be correct, but I get 404 not found error from my AJAX call. The URL the error returns adds some unfamiliar numbers to the end of it and I can't figure out why....

Here is my HTML

<script>

            load_chat("http://localhost/basecommand/index.php/ajax/chat/conversations/2");

    </script>

Here is my JS:

function load_chat(ajax_url) {
                    $.ajax({
                            type: "GET",
                            url: ajax_url,
                            dataType: "xml",
                            cache: false,
                    }
                    ).done(
                        function(){
                            $("#chat_messages").fadeOut();
                            $(xml).find('message').each(function(){
                               $("#chat_messages").append(
                               '<div class="block1"><h1>' +
                               $(this).find("author_name").text() + '</h1><p>' +
                               $(this).find("content").text() + '</p><h3>About ' +
                               $(this).find("datesent").text() + ' ago.</h3></div>'
                                )
                            });
                            $("#chat_messages").fadeIn();
                        }
                    );

        };

The error that is being returned: https://i.stack.imgur.com/jlobY.jpg

The URL works absolutely fine when I access it directly. No errors on the page, either.

ShoeLace1291
  • 4,551
  • 12
  • 45
  • 81
  • what happend if you access that URL directly? – Gonz Feb 25 '14 at 00:26
  • 2
    Those numbers are a cache breaker. This isn't the problem. – Daedalus Feb 25 '14 at 00:26
  • This is not a duplicate. I did not post that question. And the URL works absolutely fine when accessed directly. – ShoeLace1291 Feb 25 '14 at 00:26
  • @ShoeLace1291 Evan isn't saying *you* had posted that question; he means the subject matter in that question is the same as this. Which is echoed by Daedalus, that the additional element on the end is merely a GET parameter, and does not affect how your request is routed. If you're saying the URL works when accessed directly (through the browser's address bar), try it with the `?_1393...` stuff at the end; it should still work. If not, you may have something odd (admittedly I can't imagine what that might be...) interfering with your routing. – Paul Richter Feb 25 '14 at 00:46

1 Answers1

0

Checklist:

  1. The error say that the URL is not good... Check at the browser if http://localhost/basecommand/index.php/ajax/chat/conversations/2 exist. Ok, you say it works...
  2. And check if type: "GET" is correct, at jquery handbook...
  3. And XML request? What you whant to send to the ajax-webservice? I notsee in your code...
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304