大家好,我想进行休息调用并将输出重定向到 HTML 中的文本区域,我正在附加代码,请纠正我的错误(如果有),并请解释如何将休息调用的输出附加到文本区域中firebug 控制台我成功了,但我得到了一个引用错误数据未定义
<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>
最佳答案
不要让事情变得不必要的复杂。
$(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
。
关于javascript - 无法调用休息电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34084270/