JQuery form plugin - How to change the "target" (for the answer) Value

This applies to jQuery 1.3 and jQuery Form Plug 2.25.

I hope this will be a walk even for an amateur, but I do not know.

var x; $('div#response').fadeOut(300,function() { // do something x = this; } $('#myForm').ajaxForm({ target: x, success: function() { // do something } }); 

What I would like to do is define the target value as a variable that I previously defined; we will say that it is an "x". This is shown in the example above, but the string "target: x" certainly fails. How can i do this?

Also: I know that x = div # is the answer in this example, but in the real problem I'm working on, I don't have a clear definition of x. I know that in this example I could just change "target: x" to "target: div # response" and it will work, but this example is just for argument. I need a goal equal to x. How to do it?

+4
source share
2 answers

Assuming x is a complete set of jquery complete, something like this should work:

 $('#myForm').ajaxForm({ success: function(responseText, statusText) { x.html(responseText); } }); 
+3
source

Assuming your ajax call returns plain text, this should work: (You can remove the target option if you want, the x variable will be set anyway.)

 $('#myForm').ajaxForm({ target: $('#someDiv'), success: function(response) { x = response; } }); 
+2
source

All Articles