JTrixx16
JTrixx16

Reputation: 1173

Having issue with AJAX's send method

I've created a sample (index.html) where when you click the button, the box's text content must be 'Hello World', which is in the include.html file. The problem is with the send() method, which says in the console

POST http://localhost:8080/include.html 405 (Method Not Allowed)
document.querySelector.onclick @ main.js:10

here is the main.js file:

document.querySelector('button').onclick = function() {
    var xhr = new XMLHttpRequest();

    xhr.open("POST", "include.html", true);
    xhr.onreadystatechange = function() {
        if(this.readyState == 4 && this.status == 200) {
            document.querySelector('div').innerHTML = this.responseText;
        }
    }
    xhr.send();
}

Can someone help me and give me some tips about this issue? Thank you.

Upvotes: 0

Views: 34

Answers (1)

Ying Yi
Ying Yi

Reputation: 782

The 405 error means:The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource. try to use "GET" instead of "POST"

Upvotes: 1

Related Questions