日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

使用jquery调试ajax接口

發(fā)布時(shí)間:2024/9/19 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用jquery调试ajax接口 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前言

  • jquery 3.4.1
  • Google Chrome 77.0.3865.90 (正式版本) (64 位) (cohort: Stable)

方法

  • 打開 Chrome Console (F12)。
  • 讓 Chrome 加載 jquery 。
  • 執(zhí)行 jquery 的 ajax 方法。
  • 操作步驟

  • 以調(diào)用http://t.weather.sojson.com/api/weather接口(https://www.sojson.com/api/weather.html)為例進(jìn)行說(shuō)明。
    http://t.weather.sojson.com/api/weather 是接口,沒有數(shù)據(jù)。
    http://t.weather.sojson.com/api/weather/city/101030100 是接口帶參數(shù)city,獲取天津的天氣預(yù)報(bào)。
  • 在 Chrome 中打開http://t.weather.sojson.com/api/weather。這步很重要。
    沒有這步,將出現(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 中打開 Console 查看是否支持 ajax。
  • 如果Chrome已支持 ajax 方法,則跳過(guò)本步。如果Chrome未支持 ajax方法,讓 Chrome 加載 jquery 來(lái)支持 ajax 方法。
    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);
  • 執(zhí)行 jquery 的 ajax 方法。$.ajax({url: "http://t.weather.sojson.com/api/weather/city/101030100",success: function(ajaxData) {console.log(ajaxData); } });
  • 其它

    此種方式能不能使用 ajax jsonp 的方式調(diào)用?

    答:jsonp必須后端開發(fā)配合,返回的json串形式須為callback({0})、showData({0})等。得到后端開發(fā)的配合,能使用;否則,不能使用。

    總結(jié)

    以上是生活随笔為你收集整理的使用jquery调试ajax接口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。