Jump to content

Creating 2D Array from AJAX response


nano

Recommended Posts

Hello All,

 

I am currently stuck on a problem and haven't got a clue what to search, I've looked at most articles related to 2D arrays and AJAX. Sorry if this is in the wrong section of the forum, it related to JQuery, AJAX but mainly JavaScript 2D arrays.

 

I am using JQuery and want to create an array with error codes and messages.

 

Here is sample XML:

 

<resources>
    <resource name="errorCode1">Error Message One</resource>
    <resource name="errorCode2">Error Message Two</resource>
</resources>

 

Here is my current AJAX call:

 

$.ajax({
    type: "GET",
    url: "/resource.xml",
    dataType: "xml",
    success: function(xml) {
        $(xml).find('resource').each(function(){
            errorCode = $(this).attr('name');
            errorMsg = $(this).text();
        
        });
    }
});

 

What I am trying to do, somehow, is create an array that stores all error codes and error messages.

 

I then hope to pull back respective errors when searching for particular error codes.

 

Any help is greatly appreciated.

 

Cheers Guys.

Link to comment
https://forums.phpfreaks.com/topic/211262-creating-2d-array-from-ajax-response/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.