Up

module XmlHttpRequest

: sig

XmlHttpRequest object.

#
type readyState =
# | UNSENT
# | OPENED
# | HEADERS_RECEIVED
# | LOADING
# | DONE
#
class type xmlHttpRequest = ('self)
#
method onreadystatechange : (unit -> unit) Js.callback Js.writeonly_prop
#
method readyState : readyState Js.readonly_prop
#
method _open : Js.js_string Js.t -> Js.js_string Js.t -> bool Js.t -> unit Js.meth
#
method _open_full : Js.js_string Js.t -> Js.js_string Js.t -> bool Js.t -> Js.js_string Js.t Js.opt -> Js.js_string Js.t Js.opt -> unit Js.meth
#
method setRequestHeader : Js.js_string Js.t -> Js.js_string Js.t -> unit Js.meth
#
method overrideMimeType : Js.js_string Js.t -> unit Js.meth
#
method send : Js.js_string Js.t Js.opt -> unit Js.meth
#
method send_document : Dom.element Dom.document -> unit Js.meth
#
method send_formData : Form.formData Js.t -> unit Js.meth
#
method abort : unit Js.meth
#
method status : int Js.readonly_prop
#
method statusText : Js.js_string Js.t Js.readonly_prop
#
method getResponseHeader : Js.js_string Js.t -> Js.js_string Js.t Js.opt Js.meth
#
method getAllResponseHeaders : Js.js_string Js.t Js.meth
#
method responseText : Js.js_string Js.t Js.readonly_prop
#
method responseXML : Dom.element Dom.document Js.t Js.opt Js.readonly_prop
#
method ontimeout : ('self Js.t, 'self File.progressEvent Js.t) Dom.event_listener Js.writeonly_prop
#
class type xmlHttpRequestUpload = ('self)
#
val create : unit -> xmlHttpRequest Js.t

The next part of this module allow one to use Ocaml with no need for Javascript documentation.

#
module Event : sig
#
val readystatechange : xmlHttpRequest Dom.event Js.t Dom.Event.typ
#
val loadstart : typ
#
val progress : typ
#
val abort : typ
#
val error : typ
#
val load : typ
#
val timeout : typ
#
val loadend : typ
end
#
type http_frame = {
# url
: string;
# code
: int;
# headers
: string -> string option;
# content
: string;
# content_xml
: unit -> Dom.element Dom.document Js.t option;
}

The type for XHR results. The code field is the http status code of the answer. The headers field is a function associating values to any header name.

#
exception Wrong_headers of (int * (string -> string option))

The exception raise by perform functions when the check_headers parameter returned false. The parameter of the exception is a function is like the headers function of http_frame

#
val perform_raw_url : ?headers:(string * string) list -> ?content_type:string -> ?post_args:(string * Form.form_elt) list -> ?get_args:(string * string) list -> ?form_arg:Form.form_contents -> ?check_headers:(int -> (string -> string option) -> bool) -> ?progress:(int -> int -> unit) -> ?upload_progress:(int -> int -> unit) -> ?override_mime_type:string -> string -> http_frame Lwt.t

perform_raw_url ?headers ?content_type ?post_args ?get_args ?form_arg url makes an asynchronous request to the specified url with specified options. The result is a cancelable thread returning an HTTP frame. If post_args and form_arg are None, a GET request is used. If post_args or form_arg is Some _ (even Some []) then a POST request is made. The check_headers argument is run as soon as the answer code and headers are available. If it returns false, the request is canceled and the functions raise the Wrong_headers exception

#
val perform : ?headers:(string * string) list -> ?content_type:string -> ?post_args:(string * Form.form_elt) list -> ?get_args:(string * string) list -> ?form_arg:Form.form_contents -> ?check_headers:(int -> (string -> string option) -> bool) -> ?override_mime_type:string -> Url.url -> http_frame Lwt.t

perform is the same as perform_raw_url except that the Url argument has type Url.url.

#
val get : string -> http_frame Lwt.t

get url makes an asynchronous request to the specified url

end