3

この文字列をjQuery に変換する方法はありますfunction/objectか?

var str = '';
str=str+"$.ajax({ ";
str=str+"url: 'index.php', ";
str=str+"type: 'post', ";
str=str+"data: 'somevar=' + somevar, ";
str=str+"dataType: 'json', ";
str=str+"success: function(json) { ";
str=str+"alert('test'); ";
str=str+"} ";
str=str+"}); ";

私は同じ結果を得たい...

var myFunction = $.ajax({
    url: 'index.php',
    type: 'post',
    data: 'somevar=' + somevar,
    dataType: 'json',
    success: function(json) { 
        alert('test');
    }
});
4

1 に答える 1