ok, I found the problem. I didn't see it before because a) it's my
first time with jquery, and b) I'm an idiot.
Earlier I said I use .load(...) and it works fine. Now the form I'm
trying to attach the ajax post to get's loaded by that load call, so
it is not available yet on document.ready. It's a classic n00b error.
This is the former situation:

$(function() {

    $('#formdiv').load('/form/url/');       // <-- '#emailform' is
loaded here

    $('#emailform').submit(function() {
        $.ajax({
            ...
            ...
        });
        return false;
    });
});

Of-coarse it won't work, there is no '#emailform' yet to bind the ajax
call to. The later code:

$(function() {

    var bindForm = function() {
        $('#emailform').submit(function() {
            $.ajax({
                ...
                ...
            });
            return false;
        });
    }

    $('#formdiv').load('/form/url/', bindForm);       // <--
'#emailform' is loaded here, and binded with ajax call

});

The later version works fine. Thanks to the next urls I found the
answer:
http://docs.jquery.com/Tutorials:AJAX_and_Events
http://docs.jquery.com/Ajax/load#urldatacallback

Thank you James for the help, it led me to the right direction.


On Jul 3, 11:31 am, hadaraz <hada...@gmail.com> wrote:
> I see the post request, but it is not ajax:  the header is missing,
> and it is not listed in XHR section in firebug.
> Is there another way of disabling the submit action and turning it
> into ajax request? maybe that's my problem?
>
> On Jul 3, 3:26 am, James <james.gp....@gmail.com> wrote:
>
> > Earlier when you said:
> > I have used firebug, and there is no sign of AJAX request.
>
> > Did that mean there was no sign of the AJAX request firing, or no sign
> > of the X-Requested-With header?
> > Also try using a locally hosted version of jQuery 1.3.2 instead of
> > Google's. But I doubt that's the problem.
>
> > On Jul 2, 1:50 pm, hadaraz <hada...@gmail.com> wrote:
>
> > > I forgot to mention that on the same page I have  $('#loadit').load('/
> > > load/url/')  and it works fine, so the problem is only with post.
>
> > > On Jul 2, 5:32 pm, hadaraz <hada...@gmail.com> wrote:
>
> > > > Nop, it is the same...
>
> > > > On 2 יולי, 00:17, James <james.gp....@gmail.com> wrote:
>
> > > > > Hmm...
>
> > > > > What happens if you add:
> > > > > type: "POST"
>
> > > > > in your AJAX options?
>
> > > > > On Jul 1, 10:36 am, hadaraz <hada...@gmail.com> wrote:
>
> > > > > > I have used firebug, and there is no sign of AJAX request.
>
> > > > > > On the server side I use python, and yes, I'm checking for
> > > > > > 'HTTP_X_REQUESTED_WITH'. Maybe there is a problem with the jquery
> > > > > > 1.3.2 (which is what I use, linked from google ajax libs)?
>
> > > > > > On Jul 1, 9:21 pm, James <james.gp....@gmail.com> wrote:
>
> > > > > > > Have you tried using Firebug for Firefox to examine the headers 
> > > > > > > of the
> > > > > > > AJAX request to be sure that it wasn't sent? Check that first.
>
> > > > > > > You might be reading the headers incorrectly on the PHP side. Are 
> > > > > > > you
> > > > > > > using: $_SERVER['HTTP_X_REQUESTED_WITH']
> > > > > > > The beginning HTTP_ part is the tricky part. Make sure you have 
> > > > > > > that.
>
> > > > > > > On Jun 30, 9:52 pm, hadaraz <hada...@gmail.com> wrote:
>
> > > > > > > > Posting data from a form using this function:
>
> > > > > > > > $(function() {
> > > > > > > >     $('#emailform').submit(function() {
> > > > > > > >         $.ajax({
> > > > > > > >             url: '/post/url/',
> > > > > > > >             dataType: 'json',
> > > > > > > >             data: $('#emailform').serialize(),
> > > > > > > >             success: function(rdata) {
> > > > > > > >                 $('#emailformmessage').text(rdata.message).show
> > > > > > > > ('slow');
> > > > > > > >             }
> > > > > > > >         });
> > > > > > > >     });
> > > > > > > >     return false;
>
> > > > > > > > });
>
> > > > > > > > the server doesn't detect an ajax call ('X-Requested-With' 
> > > > > > > > header is
> > > > > > > > not sent). I tried forcing it with beforeSubmit and also with
> > > > > > > > ajaxSetup,  but no go.
> > > > > > > > Any solutions to this problem?
>
> > > > > > > > hadaraz-הסתר טקסט מצוטט-
>
> > > > > -הראה טקסט מצוטט-

Reply via email to