1.通过脚本访问json文件

<script type="text/javascript" src="http://localhost:8080/test.json"></script>

SyntaxError: missing ; before statement

json文件中不是js命令,执行时报错了!!


2.报错的解决:加入对返回数据的处理方法,基本解决跨域问题

JSONP详解(四)JSONP跨域访问

3.通过代码构造script块来访问json文件

$("<script><//script>").attr("src", "http://localhost:8080/test.json").appendTo("body")

图解

JSONP详解(四)JSONP跨域访问

JSONP详解(四)JSONP跨域访问

 

 

相关文章:

  • 2021-11-14
  • 2022-02-10
  • 2021-08-26
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-31
  • 2021-09-13
  • 2022-12-23
  • 2021-10-23
  • 2021-08-20
  • 2022-03-03
相关资源
相似解决方案