All Projects β†’ Lukas-Stuehrk β†’ XMLHTTPRequest

Lukas-Stuehrk / XMLHTTPRequest

Licence: MIT license
An implementation of the JavaScript XMLHTTPRequest object to extend JavaScriptCore.

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to XMLHTTPRequest

dom-lite
A small DOM library for server-side testing, rendering, and handling of HTML files
Stars: ✭ 18 (-71.43%)
Mutual labels:  xmlhttprequest
Unfetch
πŸ• Bare minimum 500b fetch polyfill.
Stars: ✭ 5,239 (+8215.87%)
Mutual labels:  xmlhttprequest
minireq
A minimal request library for the browser
Stars: ✭ 42 (-33.33%)
Mutual labels:  xmlhttprequest
angular-progress-http
[DEPRECATED] Use @angular/common/http instead
Stars: ✭ 43 (-31.75%)
Mutual labels:  xmlhttprequest
cypress-upload-file-post-form
Solution for two Cypress testing use-cases I came across with: perform a direct http FORM request to the server containing a file and other parameters and upload a file into a form before submission
Stars: ✭ 59 (-6.35%)
Mutual labels:  xmlhttprequest
ajax
Ajax wrapper for nim js backend
Stars: ✭ 18 (-71.43%)
Mutual labels:  xmlhttprequest
jscore-playground
JavaScriptCore example for Swift Playgrounds
Stars: ✭ 17 (-73.02%)
Mutual labels:  javascriptcore
browser-exploitation
A collection of curated resources and CVEs I use for research.
Stars: ✭ 71 (+12.7%)
Mutual labels:  javascriptcore
react-native-js-benchmark
JavaScript Engine Benchmark for React Native
Stars: ✭ 100 (+58.73%)
Mutual labels:  javascriptcore
JavaScriptCore-usage
JavaScriptCore-CζŽ₯口详解,δ»₯εŠεŸΊζœ¬ηš„δ½Ώη”¨ζ–Ήζ³•
Stars: ✭ 21 (-66.67%)
Mutual labels:  javascriptcore

XMLHTTPRequest

In iOS 7, Apple introduced the possibility to [execute JavaScript via the JavaScriptCore JavaScript engine] (http://nshipster.com/javascriptcore/). Unfortunately, JavaScriptCore is missing some objects and functions a JavaScript environment of a browser would have. Especially the XMLHttpRequest (see the [Mozilla documentation] (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) object needed for AJAX requests is not provided by JavaScriptCore. This library implements this missing object, so it is possible to use JavaScript libraries which were originally developed for in-browser use in your Objective-C (or Swift) application without the need to use a hidden WebView.

Provided functions

This library tries to implement the full XMLHttpRequest specification. Currently not all functionality is implemented yet. The current limitations are:

  • Synchronous calls are not supported.
  • The onload and onerror callbacks are currently not supported.
  • The upload callback is currently not supported.
  • The timeout property is currently not supported.

It is planned to support all functionality of the HTML5 specification at some point.

How to use it

Create a new instance of the XMLHTTPRequest class. Then call the extend: method and pass either a JSContext instance or a JSValue instance. The given object will be extend with the XMLHTTPRequest object.

#import <XMLHTTPRequest/XMLHTTPRequest.h>

...

JSContext *jsContext = [JSContext new];
XMLHttpRequest *xmlHttpRequest = [XMLHttpRequest new];
[xmlHttpRequest extend:jsContext];

The JavaScript context now has a XMLHTTPRequest object you can use like the object found in browsers. Example (JavaScript):

request.open('GET', 'http://example.com');
request.setRequestHeader('Accept', 'text/html');
request.setRequestHeader('X-Foo', 'bar');
request.send();

More Stuff

If you are interested in more polyfills for missing browser functionality in JavaScriptCore, there is a window timers implementation (setTimeout, setInterval, ...) called [WindowTimers] (https://github.com/Lukas-Stuehrk/WindowTimers).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].