zoukankan      html  css  js  c++  java
  • jsonp 请求报Uncaught SyntaxError: Unexpected token :

    $(document).ready(function() {
    
        jQuery.ajax({ 
            type: 'GET',
            url: 'http://wncrunners.com/admin/colors.json' ,
            dataType: 'jsonp', 
            success: function(data) { 
                alert('success');
            }
        });
    
    
      });//end document.ready
    最简单的Jsnop请求 确报Uncaught SyntaxError: Unexpected token :

    最后问了一下google,才明白

    You've told jQuery to expect a JSONP response, which is why jQuery has added the callback=jQuery16406345664265099913_1319854793396&_=1319854793399 part to the URL (you can see this in your dump of the request).

    What you're returning is JSON, not JSONP. Your response looks like

    {"red" : "#f00"}

    and jQuery is expecting something like this:

    jQuery16406345664265099913_1319854793396({"red" : "#f00"})

    If you actually need to use JSONP to get around the same origin policy, then the server serving colors.json needs to be able to actually return a JSONP response.

    If the same origin policy isn't an issue for your application, then you just need to fix the dataType in your jQuery.ajax call to be json instead of jsonp.

  • 相关阅读:
    c# 集合的交集、并集、差集
    git版本控制
    jquery html动态添加的元素绑定事件详解
    Binding笔记
    动画
    MSSQL 索引
    TCP和UDP的优缺点及区别
    Fetch API 了解 及对比ajax、axois
    提供图片服务网站
    2017 jq 总结
  • 原文地址:https://www.cnblogs.com/myzy/p/5870785.html
Copyright © 2011-2022 走看看