Book Image

Learning AngularJS for .NET Developers

By : Alex Pop
Book Image

Learning AngularJS for .NET Developers

By: Alex Pop

Overview of this book

<p>AngularJS is the most popular JavaScript MVC framework, and it embraces and extends HTML rather than abstracting it. The building of single-page applications is a web-designer-friendly process with the AngularJS expressive HTML vocabulary. It drastically reduces the amount of JavaScript required to control complex user interactions and enforces a modular approach to structuring your JavaScript code.</p> <p>This book covers all of the stages of building a single-page web application, starting with frontend components powered by AngularJS, continuing with web services that leverage ServiceStack, and putting it all together in an ASP.NET MVC application. You will learn a development process focused on rapid delivery and testability for all application layers.</p>
Table of Contents (13 chapters)
Learning AngularJS for .NET Developers
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Working with remote web services


A common occurrence for JavaScript-based applications is working with data provided by remote web services. This scenario needs to address the same-origin policy enforced by the browser, where scripts running on a page are prevented from accessing DOM elements or other resources that have a URI domain different from the URI domain of the page. A domain is defined by the combination of the URI scheme, hostname, and port number, and the same-origin policy means that a script running on a page hosted at http://example.com/main cannot make an XMLHttpRequest call for the data available at http://anotherexample.com/api/resources. To overcome this policy, there are two main techniques—JSONP (JSON with padding) and Cross-origin Resource Sharing (CORS)—that can be used, and both are supported by AngularJS.

JSONP is a technique where remote data is requested through a <script> element that is usually injected dynamically in the page at application runtime. The...