javascript - How to keep track of actions called by a jQuery dialog box? -


i have bit of dillema :)

i have link users vote on item. click on link generated jquery ajax call checking if person logged in. if not, dialog box displays form login.

but problem jquery call log in , whole bit popup box in different place.

what need check if user got logged in successfully, , update vote count.

i doing on site: http://www.problemio.com

here jquery code far:

<script type="text/javascript"> $(document).ready(function()  {      var $dialog = $('#loginpopup')        .dialog({          autoopen: false,          title: 'login dialog'        });           $("#newprofile").click(function () {           $("#login_div").hide();           $("#newprofileform").show();         });       $('.vote_up').click(function()      {                 problem_id = $(this).attr("data-problem_id");          var datastring = 'problem_id='+ problem_id + '&vote=+';          $.ajax({                 type: "post",                 url: "/problems/vote.php",                 datatype: "json",                 data: datastring,                 success: function(data)                 {                                // ? :)                     alert (data);                    },                 error : function(data)                  {                     errormessage = data.responsetext;                      if ( errormessage == "not_logged_in" )                     {                         // try create popup asks user log in.                         $dialog.dialog('open');                          // prevent default action, e.g., following link                         return false;                     }                     else                     {                         alert ("not");                     }                      //alert(json.stringify(data));                 }             });           //return false prevent page navigation         return false;     });      $('.vote_down').click(function()      {         alert("down");          problem_id = $(this).attr("data-problem_id");          var datastring = 'problem_id='+ problem_id + '&vote=-';                  //return false prevent page navigation         return false;     });     }); </script> 

it works except right after line $dialog.dialog('open'); - don't know how

  1. get signal success of fail, , don't know how
  2. update item voted on since 1 of many items can voted on in page.

how can these 2 things?

try approach:

  1. have hidden input within div login dialog.
  2. set problem_id before .dialog('open')
  3. on success callback of login button click, retrieve problem_id hidden input , perform vote-up or vote-down.

hope helps

edit: (trying code workable example after op's second comment)

<script type="text/javascript">     $(document).ready(function() {         var $dialog = $('#loginpopup')                 .dialog({                     autoopen: false,                     title: 'login dialog'                 });          var $problemid = $('#theproblemid', '#loginpopup');          $("#newprofile").click(function () {             $("#login_div").hide();             $("#newprofileform").show();         });           $('.vote_up').click(function() {             var problem_id = $(this).attr("data-problem_id");             voteup(problem_id);             //return false prevent page navigation             return false;         });          var voteup = function(problem_id) {             var datastring = 'problem_id=' + problem_id + '&vote=+';              $.ajax({                 type: "post",                 url: "/problems/vote.php",                 datatype: "json",                 data: datastring,                 success: function(data) {                     // ? :)                     alert(data);                 },                 error : function(data) {                     errormessage = data.responsetext;                     if (errormessage == "not_logged_in") {                         //set current problem id 1 within dialog                         $problemid.val(problem_id);                          // try create popup asks user log in.                         $dialog.dialog('open');                          // prevent default action, e.g., following link                         return false;                     }                     else {                         alert("not");                     }                      //alert(json.stringify(data));                 }             });         };          $('.vote_down').click(function() {             alert("down");              problem_id = $(this).attr("data-problem_id");              var datastring = 'problem_id=' + problem_id + '&vote=-';              //return false prevent page navigation             return false;         });          $('#loginbutton', '#loginpopup').click(function() {             $.ajax({                 url:'url login',                 success:function() {                     //now call cote                      voteup($problemid.val());                 }             });         });     }); </script> 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -