I have a web page on domain A and, say, a Json endpoint on domain B. I would like domain A to make an Ajax request to domain B, but when I try that, I get an error message, as shown here:
Let's explore the jsonp option. Here's a similar request to the one above, except this time it's using jsonp.
It does not raise an error.
The way jsonp works is a little wacky, but the main thing you need to know is that you need to specify a callback function. jQuery handles this automatically on the client side. Here's how I handle it on the server side with ASP.NET MVC using the Mvc.Jsonp package.
Notice three things:
The benefit is that you can now do cross-domain scripting. So far the drawbacks seems to be that:
I'm giving it a shot on Ledger, and seems to be working fine so far.
Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.