Q:AJAX如何应用?GET请求: 如果我们希望通过GET方法发送信息,请向URL添加信息: xmlhttp.open("GET", "demo.php?name=lijie&age=20", true); xmlhttp.send();
POST请求: 如果需要像HTML表单那样POST数据,请使用setRequestHeader()来添加 HTTP头。然后在send()方法中规定您希望发送的数据: xmlhttp.open("POST","demo.php",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form- urlencoded"); //向请求添加到HTTP头 xmlhttp.send("context=12111&id=99&submit=pinglun"); |