.net, ajax, jquery

Soldato
Joined
12 May 2007
Posts
3,896
Location
Bristol
Hoping someone here can help with this, been pulling my hair out for a bit.

I have a pretty neat project going now where I've done some nifty things I didn't think I'd be able to do but have now got stuck on something which should be so simple (and probably is).

I have a form being loaded into a jquery ui accordion. This is done through ajax and works great, but now I need to figure out how to serialize the form and submit it also through ajax. I can't use jquery's .serialize() as the backend is .net so there is already a form tag at the start of the page. Should also add that the form being loaded will vary greatly so I can't just grab specific name/value pairs.

Any ideas?

Edit: I should also add that each panel of my accordion could hold a different form. Each panel will have it's own submit button.
 
Last edited:
jQuery can take an object and serialize it as the for you instead of a form, something like:

Code:
$.post( "handler.ashx", 
          { 'field1': 'value1', 'field2': 'value2' },
          function() {alert('success');} 
);
 
Okay, I've run into another problem.

Code:
$('.savefunctions a').live('click', function() { 
		var fields = $(this).parents('.ui-accordion-content').find(':input');
                $.each(fields, function(i, field) {
        	alert(field.name+': "'+field.value+'", ');
        });
	});

If I have 3 inputs, this gives me one alert for each input. How would I combine them so there is only one alert containing the name:value pairs for all?
How would I combine these to just one so I can send it back to the server?
 
The backend is .net so the whole page is enclosed in a form tag and I don't want to submit the whole thing as there can be up to 20 individual forms on the page.
 
Ha. Don't I feel like a tool.

.serializeArray() works fine without a form tag so I added the json plugin and a serialize object plugin and now have it posting back as json.
 
Yeah, I'm really pushing for our company to move over to MVC as it's so much more jquery friendly but it's just a monumental task to convert our CMS over.
 
Even MVC2 uses a "super form" for the entire page. :(

Really? Do you have a source for that? I have pages where I don't need a form, and cannot find a <form> element craftily hidden away anywhere in the generated markup. I might just be misunderstanding it.
 
I have the same impression, the only forms I get are where I put in <form> or <=% Html.BeginForm(..) %> myself.

I could be doing something wrong/different/wierd though... Im not really a web guy.
 
I was also under the impression that MVC didn't use forms which is one of the reasons it's so much more jquery friendly.

If anyone else is still stuck with the evil all encompassing form tag and looking for decent client side form validation, jquerytools has a validation plugin now which works great as you don't need to target a form tag to validate. You can select all :inputs in a div and do it that way. Great when you have more than one logical form on a page with each needing separate validation.
 
Back
Top Bottom