大家好我想进行休息调用并将输出重定向到HTML中的文本区域我附加代码请更正我的错误(如果有的话)请解释如何将其余调用的输出附加到文本区域中firebug console我获得了成功,但我得到了一个没有定义的参考错误数据
<script>
$(document).ready(function()
{
$.ajax({
url:"http://127.0.0.1:8300/pink",
method: "GET",
contentType: "application/json",
dataType : "json",
success : onSuccess().bind(this),
error : function() {
console.log("Failed node Data");
}
});
});
onSuccess = function()
{
console.log("success ");
document.writeln("pinkar" + data);
}
</script>
<body>
<input name="results" id="pods"type="radio">pink
<input name="results"id="testprojects"type="radio">testpink
<input name="results" id="results" type="radio">results
<div id ="output">
<div id="podarea"style="display: none;">
<textarea id="podar" rows="4" cols="50"> </textarea>
</div>
<div id="projectarea"style="display: none;">
<textarea id="proar"rows="4" cols="50"> project area</textarea>
</div>
<div id="resultarea"style="display: none;">
<textarea id="resar" rows="4" cols="50"> resultarea</textarea>
</div>
</body>
答案 0 :(得分:1)
不要让它变得不必要。
$(document).ready(function () {
$.ajax({
url: "http://127.0.0.1:8300/pods",
method: "GET",
contentType: "application/json",
dataType: "json",
success: function(data){
// But you mentioned that returned data type is JSON, make sure to parse it.
$("#podar").html(data);
},
error: function () {
console.log("Failed node Data");
}
});
});
但是你提到返回的数据类型是JSON,请确保解析它或删除dataType:json
。