来自ajax调用的全局数组

I would like to create arrays based on the values of an ajax call and to able to use those arrays outside the ajax call (as global arrays).

This is my books.xml file:

<?xml version="1.0"?>
<root>
  <book>
    <title>title1</title>
    <pages>100</pages>
  </book>
  <book>
    <title>title2</title>
    <pages>200</pages>
  </book>
</root>

What I would like (set as global arrays):

title = array("title1","title2");
pages = array("100","200");

Thanks for your help!

You can globally declare a data object

var globalData = {
    title: [],
    pages: []
}

and in the ajax response handler function

function getData(data) {

    $(data).find("title").each(function(index, item) {
        globalData.title.push($(item).text());
    });
    $(data).find("pages").each(function(index, item) {
        globalData.pages.push($(item).text());
    });
    console.log(globalData.title, globalData.pages);

}

demo : http://jsfiddle.net/NdFDR/2/