How can I recognize touch events using jQuery in Safari for iPad? Is it possible?

Core jQuery doesn’t have anything special for touch events, but you can easily build your own using the following events touchstart touchmove touchend touchcancel For example, the touchmove document.addEventListener(‘touchmove’, function(e) { e.preventDefault(); var touch = e.touches[0]; alert(touch.pageX + ” – ” + touch.pageY); }, false); This works in most WebKit based browsers (incl. Android). Here … Read more

Set value of hidden field in a form using jQuery’s “.val()” doesn’t work

:text will fail for a input with a type value of hidden. It’s also much more efficient to just use: $(“#texens”).val(“tinkumaster”); ID attributes should be unique on a web page, make sure yours are as this may contribute to any problems you’re having, and specifying a more complicated selector just slows things down and doesn’t … Read more

$(window).width() not the same as media query

If you don’t have to support IE9 you can just use window.matchMedia() (MDN documentation). function checkPosition() { if (window.matchMedia(‘(max-width: 767px)’).matches) { //… } else { //… } } window.matchMedia is fully consistent with the CSS media queries and the browser support is quite good: http://caniuse.com/#feat=matchmedia UPDATE: If you have to support more browsers you can … Read more

How to parse JSON data with jQuery / JavaScript?

Assuming your server side script doesn’t set the proper Content-Type: application/json response header you will need to indicate to jQuery that this is JSON by using the dataType: ‘json’ parameter. Then you could use the $.each() function to loop through the data: $.ajax({ type: ‘GET’, url: ‘http://example/functions.php’, data: { get_param: ‘value’ }, dataType: ‘json’, success: … Read more

XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)

For instances where running a local webserver is not an option, you can allow Chrome access to file:// files via a browser switch. After some digging, I found this discussion, which mentions a browser switch in opening post. Run your Chrome instance with: chrome.exe –allow-file-access-from-files This may be acceptable for development environments, but little else. … Read more

Toggle input disabled attribute using jQuery

$(‘#el’).prop(‘disabled’, (i, v) => !v); The .prop() method accepts two arguments: Property name (disabled, checked, selected) anything that is either true or false Property value, can be: (empty) – returns the current value. boolean (true/false) – sets the property value. function – Is executed for each found element, the returned value is used to set … Read more

jQuery posting valid json in request body

An actual JSON request would look like this: data: ‘{“command”:”on”}’, Where you’re sending an actual JSON string. For a more general solution, use JSON.stringify() to serialize an object to JSON, like this: data: JSON.stringify({ “command”: “on” }), To support older browsers that don’t have the JSON object, use json2.js which will add it in. What’s … Read more

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