Javascript 无法拨打rest电话
大家好,我想进行rest调用并将输出重定向到HTML中的文本区域。我正在附加代码。如果有错误,请更正我的错误,并解释如何将rest调用的输出附加到firebug控制台中的文本区域。我获得了成功,但我获得了一个参考错误。未定义数据Javascript 无法拨打rest电话,javascript,jquery,html,ajax,mongodb,Javascript,Jquery,Html,Ajax,Mongodb,大家好,我想进行rest调用并将输出重定向到HTML中的文本区域。我正在附加代码。如果有错误,请更正我的错误,并解释如何将rest调用的输出附加到firebug控制台中的文本区域。我获得了成功,但我获得了一个参考错误。未定义数据 <script> $(document).ready(function() { $.ajax({ url:"http://127.0.0.1:8300/pink", method: "GET", contentType
<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>
$(文档).ready(函数()
{
$.ajax({
url:“http://127.0.0.1:8300/pink",
方法:“获取”,
contentType:“应用程序/json”,
数据类型:“json”,
成功:onSuccess().bind(此),
错误:函数(){
log(“失败的节点数据”);
}
});
});
onSuccess=函数()
{
控制台日志(“成功”);
书面文件(“pinkar”+数据);
}
粉红色
测试粉
结果
项目区
结果区
不要让它变得不必要的复杂
$(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
您好,我在firebug控制台中得到了这个消息,失败的节点数据跨源请求被阻止:同源策略不允许读取远程资源。(原因:CORS标题“Access Control Allow Origin”丢失)当我在post master插件中输入URL时,我得到一个json对象输出作为响应,这是因为您的文件上未启用CORS
。您在后端使用哪种语言?该URL已关闭MONOGDB,现在我只使用js和htmlBackend语言?不是db?是java还是python?对不起,是python