發表文章

目前顯示的是 12月, 2016的文章

Making HTTP POST Requests in JavaScript

透過Javascript實做Http 呼叫Api var http = new XMLHttpRequest(); var url = "http://localhost:25959/api/login"; var params = "acc=123123&pw=0958113359"; http.open("POST", url, true); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.onreadystatechange = function() {//Call a function when the state changes. if(http.readyState == 4 && http.status == 200) { console.log(http.responseText); } } http.send(params); readyState定義 Value State Description 0 UNSENT The open method hasn't been called yet 1 OPENED The send method has been called 2 HEADERS_RECEIVED The send method has been called and the HTTP request has returned the status and headers 3 LOADING The HTTP request response is being downloaded 4 DONE Everything has completed 文章: https://www.kirupa.com/html5/making_http_requests_js.htm

Making HTTP GET Requests in JavaScript

透過Javascript實做Http 呼叫Api var xhr = new XMLHttpRequest(); xhr.open('GET', "http://localhost:25959/api/login?Acc=123123&Pw=AA", true); xhr.send(); xhr.onreadystatechange = processRequest; function processRequest(e) { if (xhr.readyState == 4 && xhr.status == 200) { var response = JSON.parse(xhr.responseText); console.log(response.Acc); } } readyState定義 Value State Description 0 UNSENT The open method hasn't been called yet 1 OPENED The send method has been called 2 HEADERS_RECEIVED The send method has been called and the HTTP request has returned the status and headers 3 LOADING The HTTP request response is being downloaded 4 DONE Everything has completed 文章: https://www.kirupa.com/html5/making_http_requests_js.htm