1

Hi We have Rails application,

We implemented the JQuery Ajax. The Url was got excuted and got result in data object as 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>
  <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. We want get all the 5 image tag and display the impages in our application.

How can we do this with "data" object.

3
  • you have to use $.each, so you can get one by one image. Commented Dec 14, 2012 at 14:15
  • Make your application just return a scrap of HTML (drop the html) so you can embed it directly. Alternatively (and cleaner), you can have it return JSON or something like that so your can just iterate through it and handle the markup on the client side Commented Dec 14, 2012 at 14:15
  • 1
    can u post what u r getting in data object Commented Dec 14, 2012 at 14:20

2 Answers 2

1

If you are really sending back HTML data from your server this way is possible:

success: function (data, textStatus){  
  // jQuery('<selector_where_you_want_to_append').append($(data).find('img')); 
  jQuery('body').append($(data).find('img')); 
},
Sign up to request clarification or add additional context in comments.

Comments

0

You can just use $.load function in jquery if you're just loading html. 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. Here's how you can use $.load

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.