views:

4272

answers:

2

I have done jQuery and Ajax , but I am not able to get the response into a Div element. This is the code:

Index.html

       $.ajax({
   type:"POST",
   url: "ajax.php",
   data:"id="+id ,
   success: function(html){
           $("#response").html(data);
  }
      });

It is receiving the response to my <div id="response"></div>.

The ajax.php returns following code to the index.html

<div id ="one">OneVal </div>
<div id ="sub"> SubVal </div>

Will I able to extract the OneVal and Subval into a variable, and how can I extract the OneVal and SubVal, instead of above response?

+7  A: 

quite easy. you can use .find on a jquery object that was created from the response.

  success: function(data){
               //create jquery object from the response html
               var $response=$(data);
               //query the jq object for the values
               var oneval = $response.find('#one').text();
               var subval = $response.find('#sub').text();
          }
redsquare
+2  A: 

change the .find to .filter

redsquare