如何通过javascript函数将spring表单作为参数传递给ajax调用?

时间:2016-02-04 09:53:59

标签: javascript java ajax jsp

我有一个Spring表单,在JSP文件中有两个按钮。

<input type="button" onclick="saveTopicsActions(this.form)" class="btn primary publish border16" id="saveBtn" value="Save"/>
                <input type="submit" class="btn primary publish border16" id="publishBtn" value="Publish"/>

“保存”按钮的onClick()函数应将此表单作为参数并将其传递给Ajax调用。

function saveTopicsActions(form){
            jsonData={};
            jsonData = form;
            VR.appendToJSObject(jsonData);
            var jqxhr = $.post(saveTopicsActionsURL, jsonData, function(returnString) {
                if (returnString == 'true'){
                    showAutoSaveMessage();
                }else{
                    alert(returnString);
                    window.location.reload();
                }
            });
            jqxhr.error(function(data){
                //This one is highly unlikely
                alert("There was a problem  - please contact support");
                window.location.reload();
            });

但是,这是抛出javascript异常

TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement

1 个答案:

答案 0 :(得分:0)

不发送表单是DOM元素,尝试在ajax中发送值,形成JSONobject并在AJAX调用中作为parama发送。

TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement

点击上面的链接

相关问题