js ajax调用API问题
我想用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>
...全文
相关推荐
解决JS无法调用Controller问题的方法
在JavaScript中,jQuery库提供了简单易用的API来处理Ajax请求。问题描述中提到的现象是JS代码能够正常执行,但Controller的方法却没有被调用。
简单的调用百度api翻译工具js代码
**标题解析:**"简单的调用百度api翻译工具js代码" 这个标题指出我们要讨论的是一个使用JavaScript(js)来调用百度API实现翻译功能的简单应用。
JS调用C#后台方法
**JavaScript调用Web服务**: - 使用XMLHttpRequest对象或者更现代的fetch API发起异步HTTP请求。对于老版本的浏览器,可以使用jQuery的$.ajax方法。
javaScript调用C# 后代代码
总之,JavaScript调用C#后代代码涉及多种技术和工具,包括但不限于Web API、AJAX、JSON、CORS、SignalR等,这些技术共同构成了前后端通信的基础。
spring-boot-ajax:如何使用Jquery和Ajax调用rest API
本文将详细讲解如何在Spring Boot项目中使用Jquery和Ajax调用RESTful API,以实现无刷新的数据更新。


