简体   繁体   中英

Get output from method for form submitting in method for form validation in JS

I have a validation method which ends like this:

function validateForm()
{
    //do some validation
    document.imgUploadForm.submit();
}

With this, the method calls a method for submitting a form which is in a controller.

Currently, the method for handling the form returns an ActionResult.

Is there a way: HandleForm() to return JsonResult and then validateForm() to get the returned object and do stuff with it?

I tried setting JsonResult as a return type to HandleForm() and then writing:

var x = document.imgUploadForm.submit();

but x is undefined.

you need to use ajax on the client side , if you are using jQuery do :

$.getJSON("url",{input1:"value",input2:"value"},function(data){
   doSomethingWithTheDatas(data);
});

if your goal is to send something to the server , get a response and handle the response client side.

EDIT : i assume HandleForm() is server side or the question makes little sense.

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