简体   繁体   English

jQuery Ajax HTML响应

[英]Jquery Ajax Html Response

Hi We have Rails application, 嗨,我们有Rails应用程序,

We implemented the JQuery Ajax. 我们实现了JQuery Ajax。 The Url was got excuted and got result in data object as html. Url被执行,并以html的形式出现在数据对象中。

jQuery.ajax({
    type: 'GET',
    url: u,
    data: {
        id: id,
        LANG: "ENG"
    },
    dataType: 'html',
    success: function (data, textStatus) {
    },
    error: function (xhr, err, e) {
        alert("Error: " + err);
    }
});

our Html response is : 我们的HTML回应是:

<html>
  <span id='rate'>  
    <img src="www.text.comt/star.gif" width=10, height=10 >
  </span>
</html>

Actually there are 5 image tag will come the span section. 实际上,跨度部分会出现5个图片标签。 We want get all the 5 image tag and display the impages in our application. 我们要获取所有5个图像标签并在应用程序中显示缺陷。

How can we do this with "data" object. 我们该如何使用“数据”对象。

If you are really sending back HTML data from your server this way is possible: 如果您实际上是从服务器发送回HTML数据,则可以这样做:

success: function (data, textStatus){  
  // jQuery('<selector_where_you_want_to_append').append($(data).find('img')); 
  jQuery('body').append($(data).find('img')); 
},

You can just use $.load function in jquery if you're just loading html. 如果您只加载html,则可以在jquery中使用$.load函数。 I'm not really familiar on how things are done on ruby but you can also return a json string from the server and iterate over it to generate html using JavaScript. 我对如何在ruby上完成工作并不十分熟悉,但是您还可以从服务器返回一个json字符串,并对其进行迭代以使用JavaScript生成html。 Here's how you can use $.load 这是使用$.load

$('.container').load(url, {id: id,LANG: "ENG"});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM