原型到jQuery

时间:2010-08-15 17:41:19

标签: jquery prototypejs

我正在尝试将此代码从Prototype转换为JQuery:

Event.observe(window, 'load', init, false);

function init(){
 Event.observe('signup','submit',storeAddress);
}

// AJAX call sending sign up info to store-address.php
function storeAddress(event) {
 // Update user interface
 $$('response').innerHTML = 'Adding email address...';
 // Prepare query string and send AJAX request
 var pars = 'ajax=true&email=' + escape($F('email'));
 var myAjax = new Ajax.Updater('response', '/mailchimp/store-address.php', {method: 'get', parameters: pars});
 Event.stop(event); // Stop form from submitting when JS is enabled
}

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:3)

$(function() {
    $('#signup').submit(function(e) {
       var el = this;
       e.preventDefault()
       $('response').html('Adding email address');
       $.ajax({
          url:'/mailchimp/store-address.php',
          data: 'ajax=true&' + $(el).serialize(),
          success:function(){}
       });
    });
});

这应该让你开始,你可以填写缺少的部分或修改它。请记住引用API