How to make a jQuery GET/AJAX request to a private/custom URL protocol?

ios, jquery, protocols, url, webkit

Solution

The basic ajax and get methods use the browser's regular http requests. For security reasons, ajax type calls will never work with a custom protocol. If you try to develop a website that isn't on a server and use .ajax, you'll notice it will do nothing. You'll have to start from the ground up and make a custom request handler altogether, not just alter something within jQuery.

Problem

On both Mac and iOS platforms, it is possible to do two-way interchange with the native runtime through custom URI schemes / a `NSURLProtocol`. For example.. to request an `NSImage` from a native Objective-C method, you can register your custom handler (a simple string, here i used "`mycustomprotocol`") with Webkit / your `WebView NSView`, and call it from JS like… ``` var theURL = 'mycustomprotocol:///' + (textField.value); img.innerHTML = '<img src="'+theURL+'" id="string"/>'; ``` I would LIKE to be able to use jQuery to do make requests, as at this point, it is more familiar than 90's-style JS.. but as far as I can find on the web, `$.get` and `$.ajax` only do `http(s)`. Would something like ``` javascript:document.location = 'mycustomprotocol://' ``` override jquery's URL handling? I'm a dumbdumb when it comes to JavaScript, I'm sure this is easily done.. I do believe this is how the entire jQuery mobile framework is implemented (via private URI's).. So, why is there nothing on google or SO about it, huh? Can i get some help from my sister friends?

Original source

Related problems