0

I am loading AJAX content into jquery UI dialogue by clicking on a link, but it doesn't seem to work. Problem is with the popup, the link returns ajax content fine. Trying to implement this example

$.fx.speeds._default = 1000;
$(document).ready(function(){
        $( "#dialog" ).dialog({
            autoOpen: false,
            show: "blind",
            hide: "explode"
        });

    $('#<url_id>').live('click', function(evt) {
        //evt.preventDefault();
                        $.ajaxSetup({
                            async: false,   
                            "error":function() {   
                                alert("error");
                        }});
                        $.getJSON("<url>", 
                        function(data) {
                            if(data[0][0] != null){
                                var html = '';
                                html += '<div id="dialog" title="Basic dialog">';
//concatenating html
                                html += '</div>';
                            }                       
                        });
            $( "#dialog" ).dialog( "open" );
            return false;
    }); 
});

1 Answer 1

1

You havent added the element with that ID to the page yet, so your selector gets no results. You need to do something like this:

var element = $(html);
$('body').append(element);
$('#dialog').dialog();

Also: You really shouldnt set ajax defaults on every click event (it's a global setting). If you need to specify additional parameters that $.getJSON doesnt provide, you should just call $.ajax directly.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Tejs, the reason I am using $.getJSON is I can setup the async to false, for every click. I don't think I can do this with $.ajax?
You can. $.ajax is the most versatile of all the methods, and I believe the other methods (like $.getJSON) just internally call $.ajax/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.