js ajax调用API问题

star84 star84 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想用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>


...全文
评论 2
收藏 已收藏
分享
返回顶部
star84
JavaScript 87,984 成员 224,681 内容