Search code examples
jqueryajaxform

Can I use jQuery Form plugin to submit only one value to a different action URL?


I have a form that works as expected. However, I'd like to be able to do the image upload process via AJAX. For this I'm using the jQuery Form plugin. It works like a charm on one page where I could just add a separate form for the image uploading.

However, on the page I'm currently working with the image upload input is in the middle of a pre-existing form, and I can't change that.

Can anyone advise me on how I could go about using this plugin to submit only the image, to a different processing script than the main form? This can be an onclick event with a separate button.

I also need the pre-existing form to work as usual, with no AJAX involved if the normal submit button is clicked.

Is it even possible to do what I'm thinking about?


Solution

  • It should be possible provided that this the control you are adding to your form has nothing tying it into what the Pre-existing form is doing. You should be able to have jquery handle the events of the control you are adding and use Jquery ajax to call back to whatever it is you are calling back to. Instead of a button firing off an event to the server side code, you would create an HTML button and the onclick event fires a jquery function which in turn can be used to callback to your server side code - maybe a web api or a service of some kind.