Is there any way to convert this string to 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+"}); ";
I want to get the same result as...
var myFunction = $.ajax({
url: 'index.php',
type: 'post',
data: 'somevar=' + somevar,
dataType: 'json',
success: function(json) {
alert('test');
}
});
evalbut this is bad practiceCherniv, I don't think so. It doen't work - 'not a function'. Can u provide a demo?Arun P Johny, I've unparse function... stackoverflow.com/questions/17014735/…var myAjaxParamObj = { url: 'index.php', type: 'post', data: 'somevar=' + somevar, dataType: 'json', success: function(json) { alert('test'); } };