开发者

jQuery alternative to Prototypes Form.Request over ajax?

开发者 https://www.devze.com 2023-02-01 10:18 出处:网络
In prototype I could post a form to its action with its populated form data just by: $(\'form-id\').request({

In prototype I could post a form to its action with its populated form data just by:

$('form-id').request({
  onComplete: function(re开发者_如何学Csponse){ /* whatever */ }
})

I realise that I can always build my request by explicitly stating the fields like:

$.post("/my-action-url/",
   { firstformfield: $("#firstformfield").val(), second: $("#second").val() },
    function(data){
 }
); 

But for me its a big code redundancy as a lot of my application logic lies in forms, and I don't want to build extra javascript functions for every template..

I think its not so hard to do. Because you basically just have to extract the form action url, loop through all the form fields in it and build your request based on that... Of course there are some specialities like encoding and stuff, but well...

I think I could do this on my own but I wonder whether its not available yet? I didn't find it in the docs.

Also I read that jQuery supports plugin, maby theres something for that?


jQuery serialize

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号