如何将JSON数组集成到JavaScript文件中?

I have this JSON array in my JS-file:

var markers = [{"id":"1","name":"toler","lng":"110.33929824829102","lat":"-7.779369982234709","created_at":"2014-02-21 16:19:28","updated_at":"2014-02-21 16:19:28"}];

However I would need to integrate this array dynamically since I have a php file which return this array from a database.

This is the link where I can receive the JSON array.

http://localhost:8888/public/test

Is there any way to integrate this array into my JS file using this url?

Thanks!

An easy solution would be to use this:

http://api.jquery.com/jquery.getjson/

In your PHP script, have:

$json_array = json_encode(array);

Then, to get it in your JS script:

var jsonArray = <?php echo $json_array ?>;

EDIT

Now that I seem to fully understand the situation, here goes my AJAX solution suggestion. Put this in your AJAX file:

$.ajax({
    type: "post",
    url: "http://localhost:8888/public/test",
    data: { },
    success: function(response) {
        //do whatever you want here, response has your JSON array
    }
});

I would make a call to $.getJSON (or jQuery.getJSON ) and assign it to an array:

var jsonArray = null;
var url = "http://localhost:8888/public/test";
$.getJSON( url, function ( result ) {
    jsonArray = result;
});

This is just a simple snippet and you would put in your proper checks, declarations in the right places.