How do I check if string contains substring? [duplicate]

Like this: if (str.indexOf(“Yes”) >= 0) …or you can use the tilde operator: if (~str.indexOf(“Yes”)) This works because indexOf() returns -1 if the string wasn’t found at all. Note that this is case-sensitive. If you want a case-insensitive search, you can write if (str.toLowerCase().indexOf(“yes”) >= 0) Or: if (/yes/i.test(str)) The latter is a regular expression … Read more

Selecting element by data attribute with jQuery

$(‘*[data-customerID=”22″]’); You should be able to omit the *, but if I recall correctly, depending on which jQuery version you’re using, this might give faulty results. Note that for compatibility with the Selectors API (document.querySelector{,all}), the quotes around the attribute value (22) may not be omitted in this case. Also, if you work with data … Read more

Serializing to JSON in jQuery [duplicate]

JSON-js – JSON in JavaScript. To convert an object to a string, use JSON.stringify: var json_text = JSON.stringify(your_object, null, 2); To convert a JSON string to object, use JSON.parse: var your_object = JSON.parse(json_text); It was recently recommended by John Resig: …PLEASE start migrating your JSON-using applications over to Crockford’s json2.js. It is fully compatible with … Read more

How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

From the jQuery documentation: you specify the asynchronous option to be false to get a synchronous Ajax request. Then your callback can set some data before your mother function proceeds. Here”s what your code would look like if changed as suggested: beforecreate: function (node, targetNode, type, to) { jQuery.ajax({ url: ‘http://example.com/catalog/create/’ + targetNode.id + ‘?name=” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)