跨域请求的一种解决方案

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<body>
<script>
	function send(){
		$.ajax({
		url:"http://open.iciba.com/dsapi",
		data:{date:"2018-12-28"},
		dataType:"jsonp",   //加上这行代码即可
		success: function(result){
			document.getElementById('result').innerText=result.content;
			document.getElementById('tranlate').innerText=result.note;
			document.getElementById('audio1').src=result.tts;
		}
		})
	}
</script>
<div>每日一句:<span id="result"></span></div>
<hr>
<div>音频:<audio id="audio1" src="" controls="controls">
Your browser does not support the audio element.
</audio></div>
<hr>
<div>释义:<span id="tranlate"></span></div>
<button onclick="send()">发送</button>
</body>
</html>

  

猜你喜欢

转载自www.cnblogs.com/Dandwj/p/10191989.html