Giter Club home page Giter Club logo

xmlhttprequest's Introduction

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).

xmlhttprequest's People

Contributors

lukas-stuehrk avatar pjr-brenclosures avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xmlhttprequest's Issues

Duplicate symbol _ReadyState

Old project I know, but just as an FYI, after integrating this library into our project, I was getting a "Duplicate symbol _ReadyState" on compile.

To resolve I needed to precede the ReadyState NS_ENUM with typedef, i.e.

NS_ENUM(NSUInteger, ReadyState) {
XMLHttpRequestUNSENT=0, // open()has not been called yet.
XMLHTTPRequestOPENED, // send()has not been called yet.
XMLHTTPRequestHEADERS, // RECEIVED send() has been called, and headers and status are available.
XMLHTTPRequestLOADING, // Downloading; responseText holds partial data.
XMLHTTPRequestDONE // The operation is complete.
};

to

typedef NS_ENUM(NSUInteger, ReadyState) {
XMLHttpRequestUNSENT=0, // open()has not been called yet.
XMLHTTPRequestOPENED, // send()has not been called yet.
XMLHTTPRequestHEADERS, // RECEIVED send() has been called, and headers and status are available.
XMLHTTPRequestLOADING, // Downloading; responseText holds partial data.
XMLHTTPRequestDONE // The operation is complete.
};

Cheers
Peter

fetch a value from JS

Hi, I tried many times to make this done with this js but I'm failed to get value from website https://libredns.gr

this is the js code:

const byID = id => document.getElementById(id);
const TEST_URL = 'https://test.libredns.gr';
const request = new XMLHttpRequest();

request.open('GET', TEST_URL, true);

request.onload = function() {
    byID('test-success').classList.add('d-block');
};

request.onerror = function() {
    byID('test-danger').classList.add('d-block');
};

request.send();

so how can I deal with it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.