0

I'm trying to figure out a way to pass a GET variable to a Jquery UI dialog in order to be processed by some PHP. This is what I have:

$('.userjudge').click(function(){    
    var user = getID($(this).attr('id'),'UserJudge');

    $('#judgesMenu').dialog('open');

    $('#judgesMenu').data('user', user);
    $( "#judgesMenu" ).dialog({ 
        minWidth: 330,
        postition: top,
         open: function(event, ui) {
            $.ajax({
                type: "GET",
                url: "adminmenu.php",
                data: "user="+user
              });
        }
    });

    $( "#judgesMenu" ).dialog( "option", "position", 'top' );       


});

Can anyone tell me how to do this properly?

1
  • Do you need to place the HTML content of adminmenu.php?user=ID in #judgesMenu ? Have you tried to use $("#judgesMennu").load("adminmenu.php?user=ID") before opening dialog? Commented Oct 25, 2011 at 14:54

2 Answers 2

1

One problem I noticed is the way you're passing data to the jQuery ajax method. You should be doing something like this

          $.ajax({
            type: "GET",
            url: "adminmenu.php",
            data: {"user":user}
          });

You can find more information and examples of using the ajax method in the jQuery documentation at http://api.jquery.com/jQuery.ajax/

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

Comments

1

Due to lexical scoping your solution should already work. you dont need to add the "user" variable to the data of your dialog you can just reference it like you currently are. Also I moved your data directly into the url path since this looks more like what you are trying to do

$('.userjudge').click(function(){    
    var user = getID($(this).attr('id'),'UserJudge');

    $( "#judgesMenu" ).dialog({ 
        minWidth: 330,
        postition: top,
         open: function(event, ui) {
            $.ajax({
                type: "GET",
                url: "adminmenu.php?user="+user
              });
        }
    });      

    $('#judgesMenu').dialog('open');
});

3 Comments

Dialog is still not retrieving the variable =(
How are you checking that it is not getting the variable? What shows up when you put a breakpoint in the dialog open event? What does the getID() function you are calling at the beginning of the click event do?
The dialog is inside of a div on the same page--would that cause any problems?

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.