从ajax调用获取字符串版本

时间:2015-12-11 00:22:43

标签: javascript php ajax

我从ajax调用中获取了一个对象,但我需要使用该字符串。我该怎么做呢?

file1:

//some code...    

$.ajax({
type: "POST",
url: action,
data: { pictureID: pictureID, comment: comment },
error: function(xhr,status,error){alert(error);},
complete:function(data) {
document.getElementById(outputID).innerHTML = data;           
} //end of complete:function(data)
}); //end of $.ajax({

file2:

<?php
echo "test";
?>

输出:

[object Object]

需要输出:

test

1 个答案:

答案 0 :(得分:1)

将方法从完成更改为成功

$.ajax({
   type: "POST",
   url: action,
   data: { pictureID: pictureID, comment: comment },
   error: function(xhr,status,error){alert(error);},
   success:function(data) {
        document.getElementById(outputID).innerHTML = data;           
   } 
}); 

完整函数的第一个参数是jqXHR,而不是响应