0
我想調用Spring服務器中的控制器方法,該方法是在我的ReactJS頁面中的Apache服務器中使用ajax的tomcat服務器中。在tomcat控制檯中,我可以看到spring正在接收並處理它。但是,即使Spring應用程序已成功處理該調用,ajax調用也不會調用「成功」函數。 ReactJS ajax代碼中是否需要其他配置?ajax從Apache服務器中的ReactJS調用Tomcat服務器中的Spring MVC
componentDidMount: function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/SpringApp/ajaxCallTest",
data: {testId:'345'},
dataType: 'json',
success: function(response) {
alert('in success');
}
});
}
什麼都沒有? – jmartins
嘗試創建一個錯誤函數回調,如'error:function(xhr,status,err){console.error('error',status,err.toString()); }'看看是否在瀏覽器js控制檯上顯示。 – jmartins
感謝jmartins的評論。我做了你的建議,這是我從JavaScript控制檯得到的:XMLHttpRequest無法加載...沒有'Access-Control-Allow-Origin'標題出現在請求的資源上。因此不允許Origin'http:// localhost'訪問。 –