gpt4 book ai didi

java - 从 javascript (ajax) 调用 Spring Controller 方法未触发?

转载 作者:太空宇宙 更新时间:2023-11-04 07:51:49 25 4
gpt4 key购买 nike

从 javascript 向 Spring Controller 方法发出请求,如下所示

<script language="javascript" type="text/javascript">
var xmlHttp
var xmlHttp
function show()
{
if(typeof XMLHttpRequest != "undefined")
{
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlHttp==null)
{
alert("Browser does not support XMLHTTP Request")
return;
}
var FAC_LICENSE_NO=document.getElementById("FAC_LICENSE_NO").value;
//var url="/Final/WEB-INF/jsp/SurrenderViews/Ajax.jsp";
var url="http://localhost:8080/Final/Ajax.FSu";
url +="?param1="+FAC_LICENSE_NO;
alert(url);
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange()
{
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("factoryname").innerHTML=xmlHttp.responseText
}
}
</script>

和我的 Controller

public class PhaseTwoFormSurrenderOfLicense extends MultiActionController implements Connections {

public ModelAndView DataInput(HttpServletRequest request,HttpServletResponse response)
{
return new ModelAndView("SurrenderViews/DataInput");
}
public String Ajax(HttpServletRequest request,HttpServletResponse response)
{
System.out.println("Maritammanafvara");
String returning="<input type=\"text\" style=\"border: none\" name=\"Factory_name\" readonly=\"readonly\" value=\"HIHI\">";
return returning;

}
}

在上面的代码中,我可以从 html anchor 标记调用 DataInput 和 Ajax 方法,但不能从 XMLHttpRequest(ajax) 对象调用。谁能告诉一下这个地区吗?

最佳答案

你能试试吗 var url="Ajax.FSu";

而不是

var url="http://localhost:8080/Final/Ajax.FSu";

关于java - 从 javascript (ajax) 调用 Spring Controller 方法未触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14333385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com