0

我从服务器端返回 text/html: <img title="Hello World">。我的意图是在 ajax 成功回调函数中检索该标题(我正在使用 jquery 表单插件):

options_ie['success'] = function(data,statusText,xhr,form) {
    // How can I get title from "data"? 
}

我无法返回 json,因为 IE<10 将 json 响应视为文件下载。对于 FF 和 Chrome,我只需返回 json 并毫无问题地处理数据。

4

4 回答 4

0

只需在操作之前添加data

data = JSON.parse(data);
于 2013-06-25T05:53:15.750 回答
0

为此使用attr(),例如,

options_ie['success'] = function(data,statusText,xhr,form) {
    console.log($(data).find('img').attr('title'));
}
于 2013-06-25T05:12:15.380 回答
0
$.get('/myurl',function(html){
       $("#target").html(html);
       var title = $("#target img").attr("title");
    });

如果你想使用 JSON,只需使用$.getJSON(..),它适用于 IE << 10

于 2013-06-25T05:12:18.017 回答
0

您可以像这样获取标题属性。

options_ie['success'] = function(data,statusText,xhr,form) {
    var imgTitle = $(data).attr('title');
}
于 2013-06-25T05:12:25.717 回答