dongtao9095 2015-08-20 05:55
浏览 25

如何使用ajax / javascript使用单个ajax对象在不同的​​代码阶段多次向服务器发送数据

im new to javascript/ajax programming and i would like to send multiple values to the server at different stages of my program. check out my code below...

function process(){
  if(xmlHttp.readyState==0 || xmlHttp.readyState==4){
    Selected_word = document.getSelection();
    xmlHttp.open("GET","/gwizz/scripts/definition.php?word="+Selected_word,true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);

  }else{
    setTimeout('process()',1000);
  }
}

the above function "process()" will execute when a double click is triggered on the page body. the double clicked word on the body gets sent to the server and returns is definition. the definition gets displayed on top of a pop-up modal. check out the function below "handleServerResponse()" wich gets executed after "process()" is successful.

function handleServerResponse(){
  if(xmlHttp.readyState==4){
     if(xmlHttp.status==200){   
       var xmlResponse = xmlHttp.responseXML;
       var xmlDocumentElement = xmlResponse.documentElement;
       Definition = xmlDocumentElement.firstChild.data;

       $('#element_to_pop_up').bPopup({       
            onOpen:function(){
                    modal_open = time();                        
                       document.getElementById("element_to_pop_up").innerHTML = "<span style='font-weight: bold;font-size: 25pt'>"+ Selected_word;

            },
            onClose:function(){
                    modal_close = time();
                    document.getElementById("element_to_pop_up").innerHTML = "";
                    username = "beach";
                    //xmlHttp.open("GET","/gwizz/scripts/logfile.php?word="+Selected_word + "&username=" + username + "&modal_close=" + modal_close + "&modal_open=" + modal_open,true);
                    //xmlHttp.send(null);                 
            }               
     });
 }else{
    alert('Something went wrong with process!!!');  
}

}

I want to basically send other values to the server at the onClose() porperty of the modal pop-up using the same ajax object.any help would be appriciated thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试