日期:2014-05-16 浏览次数:20747 次
//这是一个用ajax提交数据的函数 //url是后台接收数据的页面,比如bookForm.php //data是要传递的数据,格式是day=3&type=2&room=2 //callback是处理服务器返回数据的函数 function postData(url, data, callback) { var request = new XMLHttpRequest(); request.open("POST", url); // POST to the specified url request.onreadystatechange = function() { // Simple event handler if (request.readyState === 4 && callback) // When response is complete callback(request); // call the callback. }; request.setRequestHeader("Content-Type", // Set Content-Type "application/x-www-form-urlencoded"); request.send(encodeFormData(data)); // Send form-encoded data }