I am creating a java script object
dynamically in my JS
file
function myfunction (data){
var illustration_db_data;
var myData= "";
if (somecondition){
illustration_db_data = {
"illustration_db_data": [
{
"illTitle": "",
"illFile1": "",
"illFile2": "",
"illFile3": "",
"illDesc": "",
"illOwner": "",
"illBc": "",
"illRights": ""
}
]
};
else{
illustration_db_data= "this is my data";
}
myData = illustration_db_data
return myData;
}
Since it is dynamic , it may be java script object or may not be.
Is there any function in JS or jQuery to check if variable is java script object
if(isJSON(myfunction (data)))
{
//do something
var myData = 'myData =' + JSON.stringify(data) + '';
$.ajax({
type: "POST",
url: "/myurl",
data: myData ,
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
}
else{
//do something else
}
=============================
Also checked the JSON in http://jsonlint.com/
and it said it is valid JSON
{
"illustration_db_data": [
{
"illTitle": "",
"illFile1": "",
"illFile2": "",
"illFile3": "",
"illDesc": "",
"illOwner": "",
"illBc": "",
"illRights": ""
}
]
}
=============================
EDIT: It would be good if solution not contain try/catch to avoid unwanted errors
it might seem very simple question but I am asking this with hope that it might help someone like me in future