Skip to content Skip to sidebar Skip to footer

Access Both Html And Json Data Returned From Ajax

I have an ajax page to return some data which contains a mix of HTML and Json data.I dont know which data type to use to extract the contents returned from ajax. Currently I used a

Solution 1:

Maybe this way: http://jsfiddle.net/IonDen/2L2gnxae/

// Some test ajax result
var result = '{"somejson", "value"}';
result += '<div>Some html</div>';

console.log(result);

// split result to json and html
var sl = result.indexOf("<");
var json = result.slice(0, sl);
var html = result.slice(sl);

console.log(json);
console.log(html);

Post a Comment for "Access Both Html And Json Data Returned From Ajax"