关于jQuery getScript跨域问题的实例代码
程序员文章站
2022-05-13 08:58:36
...
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“> <html xmlns=”www.w3.org/1999/xhtml“> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <title> jquery Ajax跨域调用|梦三秋</title> <script type=”text/ javascript ” src=”http://ajax.useso.com/ajax/libs/jquery/1.4.4/jquery.min.js”></script> </head> <body> <h1><a href=” www.skygq.com/2011/03/04/jquery-ajax跨域调用”>jquery-ajax跨域调用</a></h1> <img id=”ajax_image” src=”www.skygq.com/ci/css/img/ajax_image.gif” style=”position:absolute;z-index:10;display:none;” border=”0″/> <select id=”letter2″> <option value=””>请选择首字母</option> <option value=”A”>A</option> <option value=”B”>B</option> <option value=”C”>C</option> <option value=”D”>D</option> <option value=”E”>E</option> <option value=”F”>F</option> <option value=”G”>G</option> <option value=”H”>H</option> <option value=”I”>I</option> <option value=”J”>J</option> <option value=”K”>K</option> <option value=”L”>L</option> <option value=”M”>M</option> <option value=”N”>N</option> <option value=”X”>X</option> </select> <select id=”server2″> <option value=””>等待你选择首字母</option> </select> <script> $(function(){ $(“#letter2″).change(function(e){ var $$ = $(this); if ($$.val() != ”){ var $ajax_image = $(“#ajax_image”); var position = $$.offset(); $ajax_image.css({“top”:position.top,”left”:position.left}).show(); $(“#server2″).empty().append(“<option value=”>正在调用数据…</option>”); $.getScript(“http://113.240.253.110:8080/index.php?arg=”+$$.val(),function(){ $.each(data,function(index,name){ alert(name.id); }); if (json.length > 0){ var result = “”; $.each(json,function(index,entry){ result += “<option value='”+entry.id+”‘>”+entry.name+”</option>”; }); $(“#server2″).empty().append(result); }else{ alert(“未找到数据!”); } $ajax_image.hide(); }) } }) }); </script> </body> </html>
以上就是关于jQuery getScript跨域问题的实例代码的详细内容,更多请关注其它相关文章!