jQuery的Ajax调用返回“[对象的XMLDocument]” [英] jQuery Ajax call returning '[object XMLDocument]'

查看:247
本文介绍了jQuery的Ajax调用返回“[对象的XMLDocument]”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要使用Ajax来填充一个HTML页面。我已经复制code从其他页面,(这些都是在PHP中,我不知道,如果该事项),以及它的返回 [对象的XMLDocument] 。在其他页(PHP的)我得到什么我打印出来的程序。

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.

下面是我有:

index.html的 -

index.html -

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

在JavaScript文件 -

In the javascript file -

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

在get_help_videos.php(显然这只是暂时的code来揣摩如何工作) -

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

所以,我期待(并希望),它弹出一个警告说OK,这就是它会做在我的其他程序,但它会弹出 [对象的XMLDocument] 代替。

我是不是做错了什么?或者是它最好与它共处,并解析的XMLDocument

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

推荐答案

您需要包括你的数据类型参数AJAX调用,以表明你只是期待一个文本响应:

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

这篇关于jQuery的Ajax调用返回“[对象的XMLDocument]”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆