Daily Archives: September 22, 2008

Using The Post Method In Ajax

In the Rasmus’ 30 Second Ajax Tutorial, we’re using the get method to send our request: function sndReq(action) { http.open(’get’, ‘rpc.php?action=’+action); http.onreadystatechange = handleResponse; http.send(null); } But what if we want to use the post method? Well, let’s modify that function to do just that: function sndReq(action) { http.open(’post’, ‘rpc.php’, true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", action.length); [...]