Skip to content Skip to sidebar Skip to footer

Javascript Jquery And Using Eval

i am currenty using jquery plugin to read a data file (data.html) data.html has below format [10,20,30,40,50] my jquery data request and the javascript to return values is below f

Solution 1:

You don't need eval. Just indicate the proper dataType: 'json':

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

or even better do it asynchronously:

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

Solution 2:

I think jquery $.getScript('data.html',function(){alert("success"+$(this).text())} might be simpler. I have not had time to try it so if I'm on right track, improve this answer, if not I'm happy to learn now...

Post a Comment for "Javascript Jquery And Using Eval"