• Jquery ajax


    在现有项目的开发中,我们都采用的xml配置的方式进行开发,服务器端用相应工具生成数据的xml文件(这里我使用了Perl来生成,因为其强大的字符串处理能力),客户端采用Javascript读取xml进行相关数据的读取。

    Jquery提供的 .ajax函数可以让我们很方便地进行ajax操作。下例是一个放置图片上热点的坐标信息点:

     1 function loadHotSpot()
     2 {
     3     $.ajax(
     4     {
     5         url:"catalog/hotspot.xml",
     6         dataType:"xml",
     7         success:function(data)
     8         {
    18             $(data).find("dict").each(function(index, element) {
    19                 var left = parseInt($(this).children("x").text());
    20                 var top = parseInt($(this).children("y").text());
    21                 var imgId = parseInt($(this).children("imgId").text());
    22                 var img = "catalog/"+$(this).children("img").text();
    23                 
    24                 var spot_html = "<div class='hotspotWrapper' style='left:"+left+"px;top:"+top+"px;'><span class='hs_img'><img src='"+img+"' /></span>" ;
    25                 spot_html += "<span class='hotspot' onClick='showImg(this);'></span></div>" ;
    26                 $(".item").eq(imgId).append(spot_html);
    27             });
    28             
    29         }
    30     });
    31 }

    读取不同文件时,注意声明 dataType ,另外,注意xml的格式需要规范,否则会出错。 

  • 相关阅读:
    SQL学习记录
    Python 函数和变量作用域
    Python 使用socket实现一对多通信
    Flask wtforms validate_on_submit() 无法返回值问题
    Flask WTForm BooleanField用法
    Python3 中的nonlocal用法
    Python 实现二进制循环效果
    Python 各种类型转换
    第一章:数据结构
    Python Challenge
  • 原文地址:https://www.cnblogs.com/trying/p/3015919.html
Copyright © 2020-2023  润新知