ajax
ASP.NET Returning JSON with ASHX
context.Response.Write( jsonSerializer.Serialize( new { query = “Li”, suggestions = new[] { “Liberia”, “Libyan Arab Jamahiriya”, “Liechtenstein”, “Lithuania” }, data = new[] { “LR”, “LY”, “LI”, “LT” } } ) );
“Failed to construct ‘Blob’: The provided value cannot be converted to a sequence” when downloading file
The first parameter should be sequence. Thus, this will not work: let blob = new Blob(data, { type: “application/pdf” }); But this will: let blob = new Blob([data], { type: “application/pdf” });
Why do we pass null to XMLHttpRequest.send?
If you’ll take a look at an old specification of XMLHttpRequest, it seems like as though the W3C did not require that the parameter be optional at one point, which may have led to people supplying an explicit null value ‘just in case’. (search for ‘SHOULD support the send’) http://web.archive.org/web/20060409155734/http://www.w3.org/TR/XMLHttpRequest/ Another plausible reason I’ve come … Read more
anti-CSRF token and Javascript
There are several techniques, which when used together provide a sufficient CSRF protection. Unique Token A single, session-specific token is good enough for most applications. Just make sure that your site doesn’t have any XSS vulnerabilities, otherwise any kind of token technique you employ is a waste. AJAX call to regenerate the token is a … Read more
Cross-browser jquery ajax history with window.history.pushState and fallback
// Assuming the path is retreived and stored in a variable ‘path’ if (typeof(window.history.pushState) == ‘function’) { window.history.pushState(null, path, path); } else { window.location.hash=”#!” + path; }
JS/jQuery get HTTPRequest request headers?
If this is for debugging purposes then you can just use Firebug or Chrome Developer Tools (and whatever the feature is called in IE) to examine the network traffic from your browser to the server. An alternative would be to use something like this script: $.ajax({ url: ‘someurl’, headers:{‘foo’:’bar’}, complete: function() { alert(this.headers.foo); } }); … Read more