Search code examples
javascriptjqueryjquery-dialog

Need jQuery Dialog for confirmation and Send Ajax Request to Controller Action


i have simple tr an td's coming from database

<tr>
<td >
  <td style=" display:none"> <?php echo $record['id_to_send'];?></td>
 <?php if($record['user_value'] == 1)
 <a href="#"><img src="Green.png" /></a>
 else <a href="#"><img src="Red.png" /></a>?>
 </td>
</tr>

What i want to do is that if Green Image is clicked i want jQuery Dialog with confirm Button and if user confirm that i want to send ajax request to my Controller Action1 with data $record['id_to_send'];.if Red image is clicked after confirmation i want to send ajax request to my Controller Action2 with data $record['id_to_send'];


Solution

  • To send AJAX on OK confirmation:

    $( "<div>Confirmation</div>" ).dialog({
       modal:true,
       buttons: {
            "OK": function() {
                 sendAjax(); //Your ajax function
                 $(this).dialog( "close" );
             },
             "Cancel": function() {
                 $(this).dialog( "close" );
             }
       }
    });