单击按钮时未调用我的Javascript函数

时间:2018-08-23 07:06:20

标签: javascript spring-mvc

function createHTTPObj_newvehicle() {
    var http = null;
    if (window.XMLHttpRequest)
        http = new XMLHttpRequest();
    else if (window.ActiveXObject)
        http = new ActiveXObject("Microsoft.XMLHTTP");

   return http;
}

function newvehicle() {
    var http = createHTTPObj_newvehicle();
    debugger;
    http.open('POST', 'NavigateServlet?action=NewVehicle', true);
    http.send(null);
} 

function createHTTPObj_newbudget() {
    var http = null;
    if (window.XMLHttpRequest)
        http = new XMLHttpRequest();
    else if (window.ActiveXObject)
        http = new ActiveXObject("Microsoft.XMLHTTP");
    return http;
}

function newbudget() {    
    var http = createHTTPObj_newbudget();
    debugger;
    http.open('POST', 'NavigateServlet?action=NewBudget', true);
    http.send(null);
}

javascript页面

我在单击该Java脚本时应点击2个按钮。但我无法调用它。

<servlet>
    <servlet-name>NavigateServlet</servlet-name>
    <servlet-class>com.avigma.controller.NavigateServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>NavigateServlet</servlet-name>
    <url-pattern>/NavigateServlet</url-pattern>
</servlet-mapping>

web.xml

1 个答案:

答案 0 :(得分:0)

对于AJAX POST请求,您必须在open()之后和send()之前执行以下操作:

httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');