2013-05-13 74 views
0

我有一個獲取參數的鏈接。當我點擊它時,ajax被調用。現在,當它去使用ajax調用彈出式jquery對話框形式

action.php,我有一個PHP值(從MySQL)的形式。我想彈出與jquery

對話框。

我不知道如何做到這一點。

 <script> 


$(document).ready(function(){ 
$.ajax({ 
     type: "GET", 
     url: this.href, 
     cache:false, 
     success: function(response){   
      if (response.length > 0) { 
      document.getElementById('display').innerHTML=wrapperelement; 
       wrapperelement.innerHTML = response; 
       $("#dialog-form").dialog("open"); 
      } 
     } 
}); 
}); 
</script> 

更新代碼

該文件的正文

 <body> 
     <div id="display"></div> 
     echo '<a href="action.php?pldid=' . $pldid . '" class="editbt">Edit</a>'; 
     </body> 

所以我action.php的

if (isset($_GET['pldid'])&& $_GET['pldid']) 
{ 
$form = <<<EOF 
<form> 
<div id="dialog-form" title="Edit Fields"> 
    <p class="validateTips">All form fields are required.</p> 



<form> 
<fieldset> 
<label for="box">Box</label> 
<input type='text' name='box' id='box' class="text ui-widget-content ui-corner-all" /> 
<label for="itemname">itemname</label> 
<input type='text' name='itemname' id='itemname' class="text ui-widget-content ui-corner-all" /> 
<label for="size">size</label> 
<input type='text' name='size' id='size' class="text ui-widget-content ui-corner-all" /> 
<label for="potency">potency</label> 
<input type='text' name='potency' id='potency' class="text ui-widget-content ui-corner-all" /> 
<label for="quantity">Quantity</label> 
<input type='text' name='quantity' id='quantity' class="text ui-widget-content ui-corner-all" /> 

</fieldset> 
</form> 

</div> 
EOF; 
echo $form; 
} 

我想要的鏈接,打開了形式的窗口(來自mysql的值)。任何建議是非常歡迎..謝謝你..謝謝你..

回答

0

如果您的表單尚未在頁面上,那麼action.php應該只創建窗體的標記,所以成功,只需追加標記通過innerHTML方法,從而顯示對話。

的script.php

<?php 

$form = ""; 
if (isset($_GET['pldid']) && $_GET['pldid']) { 
    $form = <<<EOF 
<form id="dialog-form"> 
    ... 
</form> 
EOF; 
} 

echo $form; 
?> 

標記/ JavaScript的

<div id="wrapper"> 
    <!-- I'm your wrapper. I'm waiting to receive your markup --> 
</div> 

<script> 
    var wrapperelement = document.getElementById('wrapper'); 
    $.ajax({ 
      type: "GET", 
      url: this.href, 
      cache:false, 
      success: function(response){   
       if (response.length > 0) { 
        wrapperelement.innerHTML = response; 
        $("#dialog-form").dialog("open"); 
       } 
      } 
    }); 
</script> 

wrapperelement是在其中附加在服務器側產生的標記的空元素

+0

感謝您的回覆..但形式是在行動的PHP文件..對不起,我沒有提到它早... – user2234992 2013-05-13 07:33:00

+0

實際上,我想彈出窗口與窗體的PHP值..任何想法..謝謝.. – user2234992 2013-05-13 07:33:56

+0

謝謝你的編輯..但對話框形式的div ID是在行動PHP文件..會彈出?謝謝 – user2234992 2013-05-13 07:39:36

0
$.ajax({ 
      type: "GET", 
      url: this.href, 
      cache:false, 
      success: function(response){   
       if (response.length > 0) { 
        wrapperelement.innerHTML = response; 
        $("#dialog-form").dialog("open"); 
       } 
      } 
    }); 
+0

你能解釋爲什麼這將在OP已經有什麼?除了刪除一行外,您的代碼看起來幾乎完全相同 – merlinpatt 2016-12-07 07:53:56