Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax call returning '[object XMLDocument]'

I have an HTML page which I want to populate using Ajax. I've copied code from other pages, (which are all in PHP, and I'm not sure if that matters), and it's returning [object XMLDocument]. In the other pages (the PHP ones) I get whatever I printed out in the routine.

Here's what I have:

index.html -

<html> ... </html>
<script>
$(document).ready(function() {
 getSplashHelpVideos();
});
</script>

In the javascript file -

function getSplashHelpVideos() {
 $.ajax({ 
   url: "include/get_help_videos.php",
   type: "POST",
   success: function(data) {
    alert(data);
   }
 });
 return;
}

In get_help_videos.php (obviously this is just temporary code to try to figure out how this works) -

<?php
 session_start();
 echo 'OK';
 return;
?>

So I was expecting (and wanting) it to pop up an alert saying 'OK', which is what it would do in my other routines, but it pops up [object XMLDocument] instead.

Am I doing something wrong? Or is it best to live with it, and parse the XMLDocument?

like image 311
Sharon Avatar asked Apr 27 '11 21:04

Sharon


1 Answers

You need to include the datatype parameter on you AJAX call to indicate that you are simply expecting a text response:

function getSplashHelpVideos() {
    $.ajax({ 
        url: "include/get_help_videos.php",
        type: "POST",
        dataType: "text",
        success: function(data) {
            alert(data);
        }
    });
    return;
}
like image 90
Rory McCrossan Avatar answered Oct 16 '22 15:10

Rory McCrossan