简体   繁体   中英

How to pass a spring form as an argument to ajax call through javascript function?

I have a Spring Form which has two buttons in JSP file.

<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"/>

The onClick() function of Save button should take this form as an argument and pass the same to an Ajax Call.

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();
            });

But, This is throwing below the javascript exception

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

don't send a form it is DOM element, try sending the values in ajax, form a JSONobject and send as parama in the AJAX call.

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

go through the above link once

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM