Javascript jquery and using eval

I am currently using a jquery plugin to read a data file (data.html)

data.html has the format below

[10,20,30,40,50]

my jquery data request and javascript return values ​​below

function test(){
  var result=$.ajax({
    url:'data.html',
    type:'get',
    dataType:'text',
    async:false,
    cache:false
  }).responseText
return result;};
var my=test();
alert(my[0])

I want to get these values ​​in an array format. ie I want my [0] to be a value of 10, but instead I get "[". If I use the eval function

 my=eval(test());

I can get 10, but is there any other better way to save the returned ajax calls to an array instead of a string?

thank

, , myArray null ( firebug), async: false, . async: false ? (Http://stackoverflow.com/questions/133310/how-can-i-get-jquery-to-perform-a-synchronous-rather-than-asynchronous-ajax-req)

jQuery.extend({getValues: function(url) {
var result = null;
$.ajax({
    url: url,
    type: 'get',
    dataType: 'json',
    cache: false,
    success: function(data) {result = data;}
    });
return result;}});
myArray=$.getValues("data.html");
alert(myArray[1]);
0
2

eval. dataType: 'json':

function test() {
    return $.ajax({
        url: 'data.html',
        type: 'get',
        dataType: 'json',
        async: false,
        cache: false
    }).responseText;
}
var my = test();
alert(my[0]);

:

function test() {
    $.ajax({
        url: 'data.html',
        type: 'get',
        dataType: 'json',
        cache: false,
        success: function(result) {
            alert(result[0]);
        }
    });
}
test();
+5

, jquery $.getScript('data.html', function() {alert ( "success" + $(this).text())} . , , , ...

0

All Articles