Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从ajax调用获取字符串版本_Javascript_Php_Ajax - Fatal编程技术网

Javascript 从ajax调用获取字符串版本

Javascript 从ajax调用获取字符串版本,javascript,php,ajax,Javascript,Php,Ajax,我从ajax调用中获取一个对象,但我需要字符串。我该怎么做呢 文件1: 文件2: 需要输出: 将方法从完成更改为成功 $.ajax({ type: "POST", url: action, data: { pictureID: pictureID, comment: comment }, error: function(xhr,status,error){alert(error);}, success:function(data) { documen

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

文件1:

文件2:

需要输出:


将方法从完成更改为成功

$.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,而不是响应

查看“网络”选项卡并验证返回的内容。@JeremyJStarcher我不知道如何执行此操作。是时候在您喜爱的浏览器中学习基本调试了。我相信大多数浏览器通过点击F12打开调试工具。我在这里并不是粗鲁无礼——但说真的——如果你打算在JavaScript中工作,请学习调试工具和控制台。@JeremyJStarcher发现,如果我使用success而不是complete,它将打印为字符串。它改为undefined。使用console.log(数据)而不是innerHTML集,并检查浏览器控制台,您应该看到
数据
对象的结构,如果我使用success而不是complete,它将打印为字符串。为其他人更新了我的答案:)您应该解释为什么会这样做:函数
complete
的第一个参数是
jqXHR
,而不是响应。
<?php
echo "test";
?>
[object Object]
test
$.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;           
   } 
});