zoukankan      html  css  js  c++  java
  • ajax jsonp

    1     function handleResponse(resp){
    2         console.log(resp);
    3     }
    4     var script = document.createElement("script");
    5     script.src = "http://suggest.taobao.com/sug?code=utf-8&q=y&_ksTS=1382437929671_723&callback=handleResponse&k=1&area=c2c&bucketid=14";
    6     document.body.appendChild(script, document.body.lastChild);

      jq的ajax封装了dataType: "jsonp"  。那么jsonp为实现跨域,是为什么?是怎么做的?

      JSONP是通过动态<script>元素来使用的,我们都知道script标签的src属性可以引用任何一个页面的js,具有跨域功能(就跟图片的src一样),我用别人的js,不可能修改别人的数据吧,所以就不难理解为什么是“get”方式,而不可能是”post“方式了。

      本来我做这个测试,url是引的自己公司随便一个借口,结果报错,为什么呢?因为我这个借口数据是一个对象: {}这种形式,js文件不可能是{},所以报错了。在淘宝里面找的这个url ,是正确的js 才行。

  • 相关阅读:
    Counting Stars hdu
    Color it hdu
    steins;Gate
    原根
    3-idiots
    Tree
    洛谷P1352 没有上司的舞会
    洛谷P1131 时态同步
    洛谷P3177 树上染色
    Codeforces Round #617 (Div. 3)
  • 原文地址:https://www.cnblogs.com/chuyu/p/3383731.html
Copyright © 2011-2022 走看看