$.each(json.data,function(i,fb){
//some code here...
if (msg.length > 150) {
msg = msg.substr(0,200)+"...";
}
//more code here...
});
I have an issue here. If msg is not defined I got an error and I got nothing displayed on the browser.
Possible Solution: create a default message for the cases where msg is not defined.
Try:
if (msg = 'undefined') {
msg = 'some default message';
} else if (msg.length > 150) {
msg = msg.substr(0,200)+"...";
}
Issue:
The above try didn’t work because I get for each item, the same default message, instead of having the default message only for those cases were msg is no “set”.
Request:
Can I have your help in order to write the proper code so that, on each item, if msg is not defined show a default one, if otherwise, it’s site, display it ?
If you lack some information in order to proper help me, please, let me know. I’m really on a bad position right now. :s
Thanks a lot,
MEM
You have to write
==rather than=in your if-statement. Also, if you’re trying to test if it’s undefined, you should usetypeof, like this:This idea of comparing it using
typeofis actually safer than comparing it to the object calledundefined. The reason is that the object can be redefined, but the result oftypeofnever changes. I dont know why anyone would be crazy enough to do it, but it is possible to write: