Loading local files with Javascript without a web server

If you insist on using Chrome, it have some command line flags to allow access to/from local originated files (–allow-file-access-from-files / –disable-web-security). Do note that you need to run entire browser from scratch with those flags – i.e. if there’s already any other Chrome windows open flags WON’T have any effect and that effect persists … Read more

ASP.Net MVC Ajax form with jQuery validation

Try adding an OnBegin callback to the AjaxOptions and return the value of $(‘form’).validate().form() from the callback. Looking at the source it appears that this should work. function ajaxValidate() { return $(‘form’).validate().form(); } <% using (Ajax.BeginForm(“Post”, new AjaxOptions { UpdateTargetId = “GBPostList”, InsertionMode = InsertionMode.InsertBefore, OnBegin = “ajaxValidate”, OnSuccess = “getGbPostSuccess”, OnFailure = “showFaliure” })) … Read more

Chrome’s loading indicator keeps spinning during XMLHttpRequest

I shamelessly stole Oleg’s test case and adjusted it a bit to simulate long-polling. load.html: <!DOCTYPE html> <head> <title>Demonstration of the jQery.load problem</title> <script src=”http://code.jquery.com/jquery-latest.js”></script> <script> jQuery(document).ready(function() { $(‘#main’).load(“test.php”); }); </script> </head> <body> <div id=’main’></div> </body> </html> test.php: <?php sleep(5); ?> <b>OK!</b> The result is interesting: in Firefox and Opera, no loading indicator is shown … Read more

Using $.Deferred() with nested ajax calls in a loop

Yeah, using Deferred is the way to do that: function a() { var def = $.Deferred(); $.ajax(“http://url1”).done(function(data){ var requests = []; for (var i = 0; i < 2; i++) { requests.push(b()); } $.when.apply($, requests).then(function() { def.resolve(); }); }); return def.promise(); } // called by a() function b() { var def = $.Deferred(), requests = … Read more

How do you trigger the “error” callback in a jQuery AJAX call using ASP.NET MVC?

NOTE: Hey, this was posted before ASP.Net MVC even hit 1.0, and I haven’t even looked at the framework since then. You should probably stop upvoting this. Do something like this: Response.StatusCode = (int)HttpStatusCode.BadRequest; actionResult = this.Content(“Error message here”); The status code should change depending on the nature of the error; generally, 4xx for user-generated … Read more

XHR Upload Progress is 100% from the start

I also recently had some difficulty setting an event listener for XHR onprogress events. I ended up implementing it as an anonymous function, which works beautifully: xhr.upload.onprogress = function(evt) { if (evt.lengthComputable) { var percentComplete = parseInt((evt.loaded / evt.total) * 100); console.log(“Upload: ” + percentComplete + “% complete”) } }; I stumbled across a lot … Read more

CORS jQuery AJAX request

It’s easy, you should set server http response header first. The problem is not with your front-end javascript code. You need to return this header: Access-Control-Allow-Origin:* or Access-Control-Allow-Origin:your domain In Apache config files, the code is like this: Header set Access-Control-Allow-Origin “*” In nodejs,the code is like this: res.setHeader(‘Access-Control-Allow-Origin’,’*’);

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