2016-08-24 39 views
0

我創建了一個示例(index.html),其中當您單擊該按鈕時,該框的文本內容必須是「Hello World」,該文件位於include.html文件中。問題是與send()方法,它說,在控制檯AJAX的發送方法問題

POST http://localhost:8080/include.html 405(不允許的方法)
document.querySelector.onclick @ main.js:10

這裏是main.js文件:

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(); 
} 

有人可以幫助我,給我一些關於這個問題的提示嗎?謝謝。

+1

嘗試使用訪問頁面中的 「GET」,而不是 「POST」 你'xhr.open(...) ' –

+1

網絡服務器(無論使用哪一個)都不允許向include.html發送POST請求。你必須檢查服務器配置。對HTML文件的POST請求似乎沒有任何意義,因爲它無法有效地處理請求。 – David

+1

POST被鎖定。 GET可能工作,或者根本沒有訪問權限。基本上這是一個服務器端問題,而不是客戶端 – Liam

回答

1

的405錯誤是指: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. 嘗試使用 「GET」,而不是 「POST」

+0

非常感謝。你讓我避免使用jQuery的快捷方式 – JTrixx16