Rumah >hujung hadapan web >tutorial js >关于jQuery getScript跨域问题的实例代码

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

零下一度
零下一度asal
2017-06-19 13:23:191225semak imbas

<!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>

Atas ialah kandungan terperinci 关于jQuery getScript跨域问题的实例代码. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn