Home > Web Front-end > JS Tutorial > Example code about jQuery getScript cross-domain issues

Example code about jQuery getScript cross-domain issues

零下一度
Release: 2017-06-19 13:23:19
Original
1254 people have browsed it

<!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>
Copy after login

The above is the detailed content of Example code about jQuery getScript cross-domain issues. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template