我自己写的html码如下:
 <img id="BTImg" src="" width="623px" height="420px" style="z-index:1; position:absolute; margin:1px 0 0 0px; ">
JS代码:var GetBTImg = function(){
    $.ajax({
        url:'http://news.guet.cn/bcapi.asmx/next',
        type: 'POST',
        dataType: 'json',
contentType: "application/json; charset=utf-8",
data: "",
        error: function(json){
            
        },
        success: function(json){
    var jsonData = eval('('+json+')');
   
$('#BTImg').attr('src',jsonData.str);


    }
    });
};
后台数据:<string xmlns="http://tempuri.org/">
{"str":"http://news.guet.edu.cn/BeautyAPI/image/15550.jpg"}
</string>

解决方案 »

  1.   

    直接返回{"str":"http://news.guet.edu.cn/BeautyAPI/image/15550.jpg"}
    就可以实现了
      

  2.   

    你直接返回:{"str":"http://news.guet.edu.cn/BeautyAPI/image/15550.jpg"}试试看。
      

  3.   

    多谢各位我已经获取数据,如果我想做一个投票系统返回数据到后台要怎么做?http://news.guet.edu.cn/BeautyAPI/image/15550.jpg这图片是每分钟换一张的,我点击投票后返回15550给后台,要怎么才能去掉15550前面的地址呢?获取的是http://news.guet.edu.cn/BeautyAPI/image/图片名字,然后怎么返回的地址是http://news.guet.cn/bcapi.asmx/vote?=图片名字,要怎么弄?
      

  4.   

    还有如果一个如果一个地址里有多张图片,比如<string xmlns="http://tempuri.org/">
    [{"str":"http://news.guet.edu.cn/BeautyAPI/image/08120.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08100.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08020.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08030.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08040.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08060.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08070.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08080.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08090.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/00000.jpg"}]
    </string>获取的时候跟获取单张图片有什么区别?
      

  5.   

    因为后台数据是xml格式的,但是内容是json的,所以我用function GetBTImg(){ 
        //alert("Ddf");
    $.ajax({
    url:"http://news.guet.cn/bcapi.asmx/next",
     error: function(){
              
            },
    success:function(data){
    var s=$(data).find("string").text();
    alert(s);
    var te=strToJson(s);

    alert(te.str);
    $("#BTImg").attr("src",te.str);
    }
    });
    };这样获取数据,就是提取str里面的地址,这个是一张图片的,如果里面有多张图片,比如
    <string xmlns="http://tempuri.org/">
    [{"str":"http://news.guet.edu.cn/BeautyAPI/image/08120.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08100.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08020.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08030.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08040.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08060.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08070.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08080.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08090.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/00000.jpg"}]
    </string>
    那么我该怎么提取呢?