在.live()内部调用.post()

I am loading some content through ajax, and are using .live to make the submit button which was just loaded work. Inside this .live-call, I want to do a .post-call. This does not work. If I put an alert(...) just before this .post-call, the alert works.

Is there a hack for calling .post() inside a live()? As I understand it, the following code will not call the .post call. Are there any hacks to make this work.

$('#addeventsubmit').live("click", function(){

        $.post('url...', {data:...},
            function(data){
                alert("test");
            }, 'json');
    });

Edit: I am not trying to submit a form. I am clicking the button, and getting some values here and there, which I wrap into an array, and sends that through .post. I did try to do it with .ajax, and that seemed to be the solution.

are you sure you're getting valid json back? Open up the net tab in firebug (or whatever you use) and inspect the return.

Also, it's unclear from your code if you're using {data: } and then actually specifying the data element in there. I doubt you are, but that's just supposed to be an object, which jquery will serialize and post to the url.

There is nothing wrong with the post, you need to return false from click handler to prevent default browser submit of form

You have got to add a return false; to the submit of the form:

pre jQuery 1.7 (using live(...)):

$('#formID').live('submit', function(){return false;});

post jQuery 1.7 (using on(...)):

$(document).on('submit', '#formID', function(){return false;});