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

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

How to get the response of XMLHttpRequest?

You can get it by XMLHttpRequest.responseText in XMLHttpRequest.onreadystatechange when XMLHttpRequest.readyState equals to XMLHttpRequest.DONE. Here’s an example (not compatible with IE6/7). var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { alert(xhr.responseText); } } xhr.open(‘GET’, ‘http://example.com’, true); xhr.send(null); For better crossbrowser compatibility, not only with IE6/7, but also to cover some browser-specific … Read more

Pure JavaScript Send POST Data Without a Form

You can send it and insert the data to the body: var xhr = new XMLHttpRequest(); xhr.open(“POST”, yourUrl, true); xhr.setRequestHeader(‘Content-Type’, ‘application/json’); xhr.send(JSON.stringify({ value: value })); By the way, for get request: var xhr = new XMLHttpRequest(); // we defined the xhr xhr.onreadystatechange = function () { if (this.readyState != 4) return; if (this.status == 200) … Read more

Why am I getting an OPTIONS request instead of a GET request?

According to MDN, Preflighted requests Unlike simple requests (discussed above), “preflighted” requests first send an HTTP OPTIONS request header to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a … Read more

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