CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true

This is a part of security, you cannot do that. If you want to allow credentials then your Access-Control-Allow-Origin must not use *. You will have to specify the exact protocol + domain + port. For reference see these questions : Access-Control-Allow-Origin wildcard subdomains, ports and protocols Cross Origin Resource Sharing with Credentials Besides * … Read more

ASP.NET MVC controller actions that return JSON or partial html

In your action method, return Json(object) to return JSON to your page. public ActionResult SomeActionMethod() { return Json(new {foo=”bar”, baz=”Blech”}); } Then just call the action method using Ajax. You could use one of the helper methods from the ViewPage such as <%= Ajax.ActionLink(“SomeActionMethod”, new AjaxOptions {OnSuccess=”somemethod”}) %> SomeMethod would be a javascript method that … Read more

Access Control Request Headers, is added to header in AJAX request with jQuery

Here is an example how to set a request header in a jQuery Ajax call: $.ajax({ type: “POST”, beforeSend: function(request) { request.setRequestHeader(“Authority”, authorizationToken); }, url: “entities”, data: “json=” + escape(JSON.stringify(createRequestObject)), processData: false, success: function(msg) { $(“#results”).append(“The result =” + StringifyPretty(msg)); } });

Getting “net::ERR_BLOCKED_BY_CLIENT” error on some AJAX calls

AdBlockers usually have some rules, i.e. they match the URIs against some type of expression (sometimes they also match the DOM against expressions, not that this matters in this case). Having rules and expressions that just operate on a tiny bit of text (the URI) is prone to create some false-positives… Besides instructing your users … Read more

Uploading both data and files in one form using Ajax?

The problem I had was using the wrong jQuery identifier. You can upload data and files with one form using ajax. PHP + HTML <?php print_r($_POST); print_r($_FILES); ?> <form id=”data” method=”post” enctype=”multipart/form-data”> <input type=”text” name=”first” value=”Bob” /> <input type=”text” name=”middle” value=”James” /> <input type=”text” name=”last” value=”Smith” /> <input name=”image” type=”file” /> <button>Submit</button> </form> jQuery + … Read more

Handle file download from ajax post

Don’t give up so quickly, because this can be done (in modern browsers) using parts of the FileAPI: var xhr = new XMLHttpRequest(); xhr.open(‘POST’, url, true); xhr.responseType=”blob”; xhr.onload = function () { if (this.status === 200) { var blob = this.response; var filename = “”; var disposition = xhr.getResponseHeader(‘Content-Disposition’); if (disposition && disposition.indexOf(‘attachment’) !== -1) … Read more

What is the motivation behind the introduction of preflight CORS requests?

I spent some time being confused as to the purpose of the preflight request but I think I’ve got it now. The key insight is that preflight requests are not a security thing. Rather, they’re a not-changing-the-rules thing. Preflight requests have nothing to do with security, and they have no bearing on applications that are … Read more

jQuery AJAX cross domain

Use JSONP. jQuery: $.ajax({ url:”testserver.php”, dataType: ‘jsonp’, // Notice! JSONP <– P (lowercase) success:function(json){ // do stuff with json (in this case an array) alert(“Success”); }, error:function(){ alert(“Error”); } }); PHP: <?php $arr = array(“element1″,”element2”,array(“element31″,”element32”)); $arr[‘name’] = “response”; echo $_GET[‘callback’].”(“.json_encode($arr).”);”; ?> The echo might be wrong, it’s been a while since I’ve used php. In … Read more

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