Struct web::XMLHttpRequest

source ·
pub struct XMLHttpRequest(_);

Implementations§

Examples found in repository?
src/http_request.rs (line 152)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}
Examples found in repository?
src/http_request.rs (line 163)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}
Examples found in repository?
src/http_request.rs (line 167)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}
Examples found in repository?
src/http_request.rs (line 165)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}
Examples found in repository?
src/http_request.rs (line 171)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}
Examples found in repository?
src/http_request.rs (line 175)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}
Examples found in repository?
src/http_request.rs (line 176)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}
Examples found in repository?
src/http_request.rs (lines 174-178)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pub fn fetch(
    url: &str,
    action: HTTPMethod,
    body: Option<&str>,
    headers: Option<HashMap<String, String>>,
    mut callback: impl FnMut(usize, String) + Send + 'static,
) {
    let request = Arc::new(XMLHttpRequest::new());
    let r2 = request.clone();
    let method_str = match action {
        HTTPMethod::GET => "GET",
        HTTPMethod::POST => "POST",
        HTTPMethod::PUT => "PUT",
        HTTPMethod::DELETE => "DELETE",
        HTTPMethod::HEAD => "HEAD",
        HTTPMethod::OPTIONS => "OPTIONS",
        HTTPMethod::PATCH => "PATCH",
    };
    request.open(method_str, url);
    if let Some(body) = body {
        request.send_with_body(body);
    } else {
        request.send();
    }
    if let Some(headers) = headers {
        for (key, value) in headers {
            request.set_request_header(&key, &value);
        }
    }
    request.set_on_load(move || {
        let status = r2.response_status();
        let text = r2.response_text();
        callback(status, text);
    });
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.