我想用AJAX调用一个接口地址,传回来的数据显示在页面上,但是一直报错,哪位可以帮忙看一下吗,多谢。
代码是要怎么写,谢谢
下面是页面代码<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="webtest.WebForm4" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="./scripts/jquery.min.js"></script>
<script type="text/javascript">
function RequestBy(code) {
//var url = 'http://q.stock.sohu.com/hisHq?code=cn_300450&start=20171120&end=20171131&stat=3&order=D&period=d&callback=?&rt=jsonp';
var url = 'http://q.stock.sohu.com/hisHq?code=cn_300450&start=20171120&end=20171131&stat=3&order=D&period=d&callback=?'; $.ajax({
type: "get",
async: false,
url: url,
// cache: false,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "historySearchHandler",
success: function (data) {
document.getElementById("data").innerHTML = data;
alert("success");
},
error: function (xhr, status, statusText) {
alert(xhr.status);
alert(statusText);
alert(xhr);
document.getElementById("data").innerHTML = statusText;
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server"> <div>
<input id="One" type="button" value="JsCallWebService" onclick="RequestBy()" />
</div>
<div id="data">
</div>
</form>
</body>
</html>
代码是要怎么写,谢谢
下面是页面代码<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="webtest.WebForm4" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="./scripts/jquery.min.js"></script>
<script type="text/javascript">
function RequestBy(code) {
//var url = 'http://q.stock.sohu.com/hisHq?code=cn_300450&start=20171120&end=20171131&stat=3&order=D&period=d&callback=?&rt=jsonp';
var url = 'http://q.stock.sohu.com/hisHq?code=cn_300450&start=20171120&end=20171131&stat=3&order=D&period=d&callback=?'; $.ajax({
type: "get",
async: false,
url: url,
// cache: false,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "historySearchHandler",
success: function (data) {
document.getElementById("data").innerHTML = data;
alert("success");
},
error: function (xhr, status, statusText) {
alert(xhr.status);
alert(statusText);
alert(xhr);
document.getElementById("data").innerHTML = statusText;
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server"> <div>
<input id="One" type="button" value="JsCallWebService" onclick="RequestBy()" />
</div>
<div id="data">
</div>
</form>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货