Is the new link by any chance being inserted within the trigger
itself? (doesn't seem like it would work because the code takes the
href attribute from the trigger itself, not the link within it, but it
could cause something weird to happen).

Other than that, are use using event delegation or live query or some
other way of binding events that is automatically executing the
ajaxBind function on the new link when it is inserted?

On Apr 22, 9:51 pm, "s.ross" <[EMAIL PROTECTED]> wrote:
> I'm having a strange problem using $.ajax. Better to illustrate with
> the code:
>
> function ajaxBind(trigger) {
>   trigger.click(function(){
>     $.ajax({
>       type: "POST",
>       url:  $(this).attr('href'),
>       data: {
>         'authenticity_token': $
> ('input[name=authenticity_token]').val()
>       },
>       dataType: 'json',
>       beforeSend: function(xhr) {
>         xhr.setRequestHeader("Accept", "application/json");
>       },
>       // json contains id and partial keys
>       success: function(json) {
>         $('#task' + json['task']).html(json['partial']);
>       }
>     });
>     return false;
>   });
>
> }
>
> When the DOM element "trigger" is clicked, a request to the server is
> issued and the JSON response comes back. Hokey, dokey. The response is
> an html link. Something along the lines of:
>
> partial: "link in html that google would strip out anyway"
>
> This gets inserted using the html() function, as you see in the
> success: part of the $.ajax call, and all is well until I click on the
> new link. Then the link is interpreted as a request to open a document
> of type application/json. Firebug doesn't reveal anything unusual
> about the inserted HTML. Does anyone see the problem here?
>
> Thanks

Reply via email to