Nginx跨域问题的案例演示
生活随笔
收集整理的這篇文章主要介紹了
Nginx跨域问题的案例演示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
跨域問題的案例演示
出現跨域問題會有什么效果?,接下來通過一個需求來給大家演示下:
?(1)nginx的html目錄下新建一個a.html
<html><head><meta charset="utf-8"><title>跨域問題演示</title><script src="jquery.js"></script><script>$(function(){$("#btn").click(function(){$.get('http://192.168.200.133:8080/getUser',function(data){alert(JSON.stringify(data));});});});</script></head><body><input type="button" value="獲取數據" id="btn"/></body> </html>(2)在nginx.conf配置如下內容
server{listen 8080;server_name localhost;location /getUser{default_type application/json;return 200 '{"id":1,"name":"TOM","age":18}';} } server{listen 80;server_name localhost;location /{root html;index index.html;} }(3)通過瀏覽器訪問測試
總結
以上是生活随笔為你收集整理的Nginx跨域问题的案例演示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx跨域问题的原因分析
- 下一篇: Nginx解决跨域问题的具体实现