回调不调用上响应

问题描述:

我有像回调不调用上响应

<div class="panel-heading"> 
    Log Messages&nbsp;&nbsp;&nbsp; <button type="button" class="btn btn-primary" onclick="onrefresh()">Fetch New Messages</button> 
</div> 

所涉及的js UI代码是

var dt = $(document).ready(function() { 
    var hostName = 'http://127.0.0.1:7101'; 
    ...some code 

}); 

function onrefresh(){ 
    console.log("he viti"); 
    xmlhttp = new XMLHttpRequest(); 
    var url = "http://127.0.0.1:7101/LogAnalyzer-RESTWebService-context-root/rest/v1/LogMessagesVORest"; 
    xmlhttp.open("POST", url, true); 
    xmlhttp.setRequestHeader("Content-type", "application/vnd.oracle.adf.action+json"); 
    xmlhttp.onreadystatechange = function() {//Call a function when the state changes. 
     if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
      alert('we are back'); 
      location.reload(); 
     } 
    } 
    xmlhttp.send(JSON.stringify(parameters));  
} 

回调不会在onrefresh方法发生。但是,我已经注意到,在顶部涉及jQuery的那里的方法,它工作正常。

+0

你的意思是'警报()'是不是之前'location.reload称为()'发生? – guest271314

+1

出于好奇,如果您使用jQuery,为什么不使用jQuery的AJAX方法? – j08691

+0

你希望我们能做些什么?这不像我们可以测试您的服务器或查看您的开发人员工具。你做了什么调试?参数定义在哪里?你的服务器是否收到请求?如果是这样,它发送了什么?你是否在'if'之外尝试过'alert()'? – 2016-09-23 19:25:37

试试这个

request.addEventListener('load', function(event) { 
    if (request.status >= 200 && request.status < 300) { 
     console.log(request.responseText); 
    } else { 
     console.warn(request.statusText, request.responseText); 
    } 
}); 
+0

我的代码的哪一部分应该将 – Vik

+0

@Vik xmlhttp.onreadystatechange替换为xmlhttp。 addEventListener –

+0

我得到log-messages.js:184未捕获的ReferenceError:请求未定义 – Vik