使用jquery调试ajax接口
生活随笔
收集整理的這篇文章主要介紹了
使用jquery调试ajax接口
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前言
- jquery 3.4.1
- Google Chrome 77.0.3865.90 (正式版本) (64 位) (cohort: Stable)
方法
操作步驟
http://t.weather.sojson.com/api/weather 是接口,沒有數(shù)據(jù)。
http://t.weather.sojson.com/api/weather/city/101030100 是接口帶參數(shù)city,獲取天津的天氣預(yù)報(bào)。
沒有這步,將出現(xiàn)跨域請(qǐng)求異常(Access to XMLHttpRequest at ‘http://t.weather.sojson.com/api/weather/city/101030100’ from origin ‘chrome-search://local-ntp’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.)。
Chrome 加載 jquery 的代碼:var script=document.createElement("script"); script.type="text/javascript"; script.src="https://code.jquery.com/jquery-3.4.1.min.js"; document.getElementsByTagName('head')[0].appendChild(script);
其它
此種方式能不能使用 ajax jsonp 的方式調(diào)用?
答:jsonp必須后端開發(fā)配合,返回的json串形式須為callback({0})、showData({0})等。得到后端開發(fā)的配合,能使用;否則,不能使用。
總結(jié)
以上是生活随笔為你收集整理的使用jquery调试ajax接口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 马斯克旗下的X平台开始从付费订阅获利 与
- 下一篇: Nothing OS 2.5 公测版发布