2012-03-03 10 views
0

jqueryダイアログ()を使用しているので、ポップアップが表示されます。ポップアップに情報を表示するPHP関数を呼びたいと思います。 私のコードは、その後、私は以下の機能を持っているjqueryダイアログ内の関数を呼び出す

$(document).ready(function() { 
       $("#dialog-form") 
        .dialog({ 
         autoOpen: false, 
         title: "Add Images", 
         //buttons: {"Cancel": function() { $(this).dialog("close"); }}, 
         draggable: false, 
         resizable: false 
       }); 

       $("#addImage").click(function() { 
        $("#dialog-form").dialog("open"); 
        return false; 
       }); 
       }); 
    <button id="addImage">Add Image</button> 
     <div id="dialog-form"> <?php function show_php(); ?> 
     </div> 

である:( は を「私はここにPHPのコードを配置する必要があり、」エコー) 関数show_phpを。 関数show_php()を呼び出すにはどうすればいいですか?これはjqueryダイアログ();を使用して可能ですか?

+0

PHPが最初に実行されます。結果はブラウザに送られます。その後、JavaScriptを実行します。それはPHPについて知りません。もちろん、 'show_php()'がHTMLに返すものをクライアントに送る前に置くことができます。または、Ajax経由でコンテンツを読み込むこともできます。 –

+0

ajaxをサーバーに呼び出すと、関数を実行し、htmlまたはdataを返すファイルにすることができます。 HTMLの場合は、ダイアログが開く前にダイアログに挿入することも、ダイアログ内のユーザーイベントから挿入することもできます。あなたが何を起こそうとしているのか、どのイベントに基づいているかについてもっと知る必要があります – charlietfl

答えて

0

クエリダイアログのopenイベントを使用して、ajax呼び出しをトリガーして入力します。

$("#dialog-form").dialog({ 
    open: function(event, ui) { 
    // Here you make an ajax call to load the content of the dialog from the server 
    } 
}); 
0
you can use ajax by modifying your current file like this 


$(document).ready(function() { 
        $("#dialog-form") 
         .dialog({ 
          autoOpen: false, 
          title: "Add Images", 
          //buttons: {"Cancel": function() { $(this).dialog("close"); }}, 
          draggable: false, 
          resizable: false 
        }); 

        $("#addImage").click(function() { 
         $.ajax({ 
        url: "show.php", //it now afile where your function is and you want to run 
        type: "GET",   
        data: data, //any data you want to send to php file/function 
        cache: false, 
       success: function (html) { 


       //add the content retrieved from ajax and put it in the #content div 
       $('#dialog-form').html(html); //will add the content from the php to div 

      }  
     }); 
         $("#dialog-form").dialog("open"); 
         return false; 
        }); 
        }); 
     <button id="addImage">Add Image</button> 
      <div id="dialog-form"> <?php function show_php(); ?> 
      </div> 
4
$('#addImage').click(function() { 
    $('#dialog-form').load('show.php').dialog({ 
     autoOpen : false, 
     title : 'dialog title', 
     width : 400, 
     position : ['center', 'middle'], 
     modal : true, 
     resizable: false, 
     buttons: { 
      'OK' : function() { 
       $(this).dialog("close"); 
      } 
     } 
    }).dialog('open'); 
    return false; 
}); 

show.php 
<?php 
    echo "this is show.php"; 
?> 

or 

$('<div />').load('show.php').dialog({ 
    ...... 
}); 
+1

jQueryからPHP関数を決して*直接*呼び出さない方法についてOPに説明したいと思うかもしれませんが、AJAX経由で行う必要があります。 – JasonWyatt

関連する問題