Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

David Müller:
Cross Domain AJAX Guide
Dec 10, 2012 @ 18:17:39

In his latest post David Müller covers some of the things to consider when working with cross-domain ajax requests including CORS and iframes.

As it is widely known, AJAX Requests are only possible if port, protocol and domain of sender and receiver are equal. [...] Having this cleared out, we will cover ways around this restriction.

He covers three main approaches to allowing these cross-domain requests (and some of the security implications that can come with them):

  • CORS (Cross Origin Resource Sharing)
  • JSONP (Javascript with a local domain callback)
  • Iframes

He also briefly mentions things like window.postMessage (HTML5) and the use of a backend script to proxy a request into your application's local code.

tagged: crossdomain ajax cors iframe jsonp tutorial introduction

Link:

Lorna Mitchell's Blog:
Building A RESTful PHP Server: Output Handlers
Feb 01, 2012 @ 16:25:33

Lorna Mitchell is back with another post in her "Building a RESTful PHP Server" series today with this new post showing how to work with output handlers (her focus is on JSON).

So far we've covered parsing requests to determine exactly what the user is asking for, and also looked at routing to a controller to obtain the data or perform the action required. This post gives examples of how to return the data to the client in a good way.

She advocates using output handlers instead of the usual views you'd think of in a typical MVCish sort of application. The difference here is that there's not a lot of extra overhead to produce the results - it's literally an output directly from a class extending the base view (including the correct headers). She also briefly mentions the inclusion of JSONP functionality, allowing you to specify a local callback to execute when the request is returned. A few other "nice to haves" are also mentioned like the number of results returned and pagination support.

tagged: output handler restful server json jsonp tutorial view

Link:

WebSpeaks.in:
Cross Domain Posting using PHP and JavaScript: ITS POSSIBLE!
Dec 21, 2010 @ 17:51:35

Ever been frustrated by the fact that your javascript code can't make JSON requests to sites under other other domains? Well, WebSpeaks.in has some happy news for you in the form of JSONP.

Well.....finally i have worked out how to post cross-domain data which is restricted by browser's security policies. What is it?? This will be used for posting AJAX requests via java-script to any web-service or web-page in any DOMAIN and also get back the results from there.

JSONP allows you to call a URL outside of the domain the script is running from with a callback. This callback lives in the calling script so, technically, it never leaves that scope. There's lots of other resources out there to help you implement it in your own code including jQuery and Prototype JSON handling.

tagged: crossdomain javascript jsonp tutorial

Link:


Trending Topics: