- You may visit http://www.anapioficeandfire.com/api/books plain as day in a browser, but if you try to slurp the JSON object there down into some jQuery AJAX at an .html page on your desktop that you are just running through Google Chrome you may be in for some heartache. In looking a Fiddler, you see the call consumed successfully and yet the in-page .ajax call falls over to it's error method. Why so? Partway into this is this copy: Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. Extensions aren't so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions. Ah-ha! That has half of the answer for what to do and the rest may be found here, and yes there is a solution. It's not that the thing you are consuming needs to open up CORS permissions, but instead it does actually have something to do with you. Open the command prompt as administrator and navigate to where Chrome lives. On my laptop that is at: C:\Program Files (x86)\Google\Chrome\Application ...then run this command: chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security ...to get a version of Google Chrome with watered-down security. Remember, it worked in Fiddler. It's just Chrome itself that is cantankerous. There is a second step and that is to use async:false/crossDomain:true/dataType:'json' like so:
$.ajax({
url: 'http://www.anapioficeandfire.com/api/books',
type: "GET",
async: false,
crossDomain: true,
dataType: 'json',
success: function(result) { console.log(result); alert('Success'); },
error: function(result) { alert('Failed!'); }
}); - jsbin.com is an interesting place to build and test JavaScript.
- A C# using statement is not taking a try/catch/finally shape in CLR. It has a try/finally vibe. If an exception is thrown in the try part, the finally part still runs (the Dispose method for the IDisposable implementation) but the exception is not caught and "handled." It bubbles right up to you!
- There is a .hasClass in jQuery that goes with the .addClass and .removeClass stuff.
- A gist at GitHub allows for you to save and share a code snippet without dedicating a repository to as much.
- Yes, internal classes may be seen outside of their immediate project in a C# solution by creating a friend relationship between two assemblies.
- The memory leak in Angular's two-way data binding has been significantly improved between version 1.3 and version 1.5.8.
- Try to always use the strictly equals in JavaScript comparisons as the == operator might allow for 6 and "6" to be equal and hence allow for code to blow up downstream.
Tuesday, November 1, 2016
some assorted notes from a set of recent interviews
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment