【发布时间】:2015-08-14 14:18:29
【问题描述】:
我还需要发布数据并显示它。我正在使用ajax post方法。我能够获取保存数据的事件 ID,但无法显示数据。我搜索了很多,也得到了一些答案。我在我的代码中尝试过,但没有得到结果。我的代码是:
<!DOCTYPE html>
<html>
<head>
<title>POST API</title>
<script type="text/javascript" src="http://ajax.googleapis.com /ajax/libs /jquery/1.2.6/jquery.js"></script>
</head>
<body>
<button id="btn1">Check HTTP POST</button>
<p>Display sample output from POST API:</p>
<p id="one" />wEventId :
<p id="two" />
<script>
$(document).ready(function() {
$("#btn1").click(function() {
$.ajax({
url: 'url',
dataType: 'json',
type: 'POST',
crossDomain: true,
contentType: 'application/json',
data: {},
success: function(data) {
console.log(data);
document.getElementById("two").innerHTML = data.result.wEventId;
},
failure: function(errMsg) {
console.log(errMsg);
}
var myData = data;
myData = new Array;
});
});
});
</script>
</body>
</html>
请任何人帮助我如何修改代码以打印保存的数据。我没有给出网址,因为它是一个内部服务器,不应该透露它。提前致谢。
【问题讨论】:
-
p 标签不会自动关闭。
-
除了
cookie处理stackoverflow.com/questions/31821245之外,这可能很有用 -
@atinder 但这并没有给出任何错误
-
浏览器不会为不正确的 html 提供任何错误。
-
@ArcanaRoy 您能否在问题本身中向我们展示您的完整 json。
标签: javascript jquery html ajax