jQuery中Ajax的get、post等方法详解

2020-05-23 06:01:09易采站长站整理

  }

使用JSONP形式的回调函数来加载其他网站的JSON数据。例如:


<!DOCTYPE html>
<html>
<head lang=”en”>
    <meta charset=”UTF-8″>
    <script src=”../../js/jquery-2.1.3.js”></script>
    <style>
        * { margin:0; padding:0;}
        body { font-size:12px;}
        .para {
            width:100px;
            height:100px;
            margin:5px;
            border:0;
        }
    </style>
    <title></title>
</head>
<body>
<p>
    <input type=”button” id=”send” value=”加载”/>
</p>
<div id=”resText” >
</div>
</body>
<script type=”text/javascript”>
    $(function () {
        $(‘#send’).click(function() {
            $.getJSON(“https://api.flickr.com/services/feeds/photos_public.gne?tags=car&tagmode=any&format=json&jsoncallback=?”,
                    function(data){
                        $.each(data.items, function( i,item ){
                            $(“<img class=’para’/> “).attr(“src”, item.media.m).appendTo(“#resText”);
                            if ( i == 3 ) {
                                return false;
                            }
                        });