首页 >web前端 >js教程 >关于jQuery getScript跨域问题的实例代码

关于jQuery getScript跨域问题的实例代码

零下一度
零下一度原创
2017-06-19 13:23:191222浏览

<!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=&#39;”+entry.id+”‘>”+entry.name+”</option>”;
     });
     $(“#server2″).empty().append(result);
    }else{
     alert(“未找到数据!”);
    }
    $ajax_image.hide();
   })
  }
 })
});
</script>
</body>
</html>

以上是关于jQuery getScript跨域问题的实例代码的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn