日期:2014-05-16  浏览次数:20366 次

Js和ajax进行交互

<script>
function apply(){
???var oForm = document.forms[0];?
???var sBody = getRequestBody(oForm);
???var oXMLHttp = createXMLHttp(); // 取得 XMLHttp对象????
???oXMLHttp.open("post","/CSN/InterE2EServlet?type=2",true);????
???// 注意下面利用XMLHttp对象对请求头Content-Type的设置????
???oXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
???oXMLHttp.onreadystatechange = function() {????
????if (oXMLHttp.readyState == 4) {????
?????if (oXMLHttp.status == 200) {
?????var orderNo = oXMLHttp.responseText;
?????if(orderNo=="提交订单时出现错误!"){
??????alert("提交订单时出现错误!");
?????}else{
??????if(confirm(orderNo+",是否要转到详细信息页面?")){
??????window.location.href="/CSN/InterE2EServlet?type=4&ORDER_SERVICE_NO="+orderNo.substring(4);
??????}
?????}
????}????
???}????
??}
??oXMLHttp.send(sBody);
}

?

下面用到的是一个js导入到自己的文件中就可以了