0

i have xml look like this:

<batch>
<status>true</status> 
<sub_batch>
<batchNO>TEST1</batchNO>
<batchExpiry>TEST1</batchExpiry>
<batchQty>51</batchQty>
</sub_batch>
<sub_batch>
<batchNO>TEST2</batchNO>
<batchExpiry>TEST2</batchExpiry>
<batchQty>52</batchQty>
</sub_batch>
<sub_batch>
<batchNO>TEST3</batchNO>
<batchExpiry>TEST3</batchExpiry>
<batchQty>53</batchQty>
</sub_batch> 
</batch>

my jquery look like this:

                    $.ajax({
                    type: "GET",
                    url: "../inventory_ajax/di_get_batch.jsp?dinvid="+prd_di_inv_id,
                    dataType: "xml",
                    async: false,
                    success: function(xml){             

                    $('sub_batch', xml).each(function(){
                    var value = $(this).attr('value');
                    var label = $(this).text();

                    });

                    },
                    error: function() {
                    alert("An error occurred while processing XML file.");
                    }
                    });  

how do i get it work by getting its value for each sub_batch and its content like batchNo/batchExpiry/batchQTY

thanks

2
  • The sub_batch elements don't have a value attribute. What are you expecting to get with that? Commented Jul 1, 2014 at 4:37
  • You can use $('batchNO', this) to access the batchNo element within the sub_batch. Commented Jul 1, 2014 at 4:38

1 Answer 1

1

Try,

 $('sub_batch',xml).each(function () {
     $(this).children().each(function () {
         alert($(this).prop('tagName') + ":" + $(this).text());
     })
 });

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

$(xml).find('sub_batch').each(function(){ var label = $('batchNO', this).text(); console.log(label); this work fine });
@David Glad my idea has helped you..!

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.