mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +00:00
LibWeb: Add XMLHttpRequest.readyState and constants
This commit is contained in:
parent
3c9693c6c7
commit
602a36970f
Notes:
sideshowbarker
2024-07-19 07:23:21 +09:00
Author: https://github.com/linusg
Commit: 602a36970f
Pull-request: https://github.com/SerenityOS/serenity/pull/1925
Reviewed-by: https://github.com/awesomekling
5 changed files with 46 additions and 0 deletions
|
@ -46,6 +46,12 @@ XMLHttpRequest::~XMLHttpRequest()
|
|||
{
|
||||
}
|
||||
|
||||
void XMLHttpRequest::set_ready_state(ReadyState ready_state)
|
||||
{
|
||||
// FIXME: call onreadystatechange once we have that
|
||||
m_ready_state = ready_state;
|
||||
}
|
||||
|
||||
String XMLHttpRequest::response_text() const
|
||||
{
|
||||
if (m_response.is_null())
|
||||
|
@ -57,22 +63,27 @@ void XMLHttpRequest::open(const String& method, const String& url)
|
|||
{
|
||||
m_method = method;
|
||||
m_url = url;
|
||||
set_ready_state(ReadyState::Opened);
|
||||
}
|
||||
|
||||
void XMLHttpRequest::send()
|
||||
{
|
||||
// FIXME: in order to properly set ReadyState::HeadersReceived and ReadyState::Loading,
|
||||
// we need to make ResourceLoader give us more detailed updates than just "done" and "error".
|
||||
ResourceLoader::the().load(
|
||||
m_window->document().complete_url(m_url),
|
||||
[weak_this = make_weak_ptr()](auto& data) {
|
||||
if (!weak_this)
|
||||
return;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).m_response = data;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done);
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(Event::create("load"));
|
||||
},
|
||||
[weak_this = make_weak_ptr()](auto& error) {
|
||||
if (!weak_this)
|
||||
return;
|
||||
dbg() << "XHR failed to load: " << error;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done);
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(Event::create("error"));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue