JS 跨域

根据同源策略  浏览器会禁止跨域

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    function show(data){
      console.log(data);
    }

$(function(){
    // $.ajax({
    //     url: 'http://fanyi.youdao.com/openapi.do',
    //     type: 'GET',
    //     dataType: 'json',
    //     data: {
    //         'keyfrom': 'rakustrans',
    //         'key': '1506707246',
    //         'type': 'data',
    //         'doctype': 'json',
    //         'version': '1.1',
    //         'q': 'seti'
    //     },
    // }).done(function(data) {
    //     console.log(data);
    //     notif({
    //         msg: data,
    //         type: "success"
    //     });
    // }).fail(function() {
    //     console.log("error");
    // }).always(function() {
    //     console.log("complete");
    // });

    function show(data){
      console.log(data);
    }
    $.ajax({
      url: 'http://fanyi.youdao.com/openapi.do?keyfrom=rakustrans&key=1506707246&type=data&doctype=jsonp&callback=show&version=1.1&q=API',
      dataType: 'jsonp'
    })
    .done(function() {
      console.log("success");
    })
    .fail(function() {
      console.log("error");
    })
    .always(function() {
      console.log("complete");
    });


});


</script>
</body>
</html>

 

posted @ 2014-06-22 16:42  cart55free99  阅读(136)  评论(0编辑  收藏  举报