开发者

posting to aweber with jQuery

Im trying to post to aweber using just jquery. I have a method call like this

$(function () {
            $('#submit').click(function () {
                $.post('http://www.aweber.com/scripts/addlead.pl',
                {
                    meta_web_form_id: '12345',
                    meta_split_id: '',
                    listname: 'some_list',
                    redirect: '',
                    meta_redirect_onlist: '',
                    meta_adtracking: 'my_Web_Form',
                    meta_message: '1',
                    meta_required: 'name,email',
                    meta_forward_vars: '',
                    meta_tooltip: '',
                    email : 'test@happy.com',
                    name : 'tester testing'
                },
                function (data) {
             开发者_如何转开发       alert('data load: ' + data);
                });
            });
        });   

it is supposed to take the result of the post and alert it in a box. when i try to do it manually with forms it works but redirects me to a 'form-sorry.htm' page, which is fine, just wondering if there was a way to display the end result of the post. Im guessing hte addlead.pl is just a posting page with no response.


Your $.post() data looks okay but since you're attaching a click handler to your submit button, the form will still function normally and redirect. The data is also being sent via $.post() at the same time.

Here I'm using jQuery .submit() and grabbing the name and email values dynamically to be used in the $.post() method. I then clear the form by resetting it, display a confirmation message to the user, and return false; to prevent the normal form functionality.

For displaying the end result you can always do alert(data); before the return false; but it will show as an object, so you'd have to work with that.

You could also check the network tab in Chrome Dev Tools for your post and the data being sent.

Hope this helps.

$('#form_id').submit(function() {
    var nameVal = $('input[name="name"]').val();
    var emailVal = $('input[name="email"]').val();

    $.post('http://www.aweber.com/scripts/addlead.pl', {
        meta_web_form_id:   '123456789',
        meta_split_id:      '',
        listname:           'listNameHere',
        redirect:           '',
        meta_adtracking:    'newsletter',
        meta_message:       '1',
        meta_required:      'name,email',
        meta_tooltip:       '',
        name:               nameVal,
        email:              emailVal
    });

    $('#form_id')[0].reset();

    alert('Email sent!');

    return false;
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜