2015-05-04 62 views
1

我想從對話框窗口中的輸入文本字段獲取輸入以將它們用於SQL查詢。我的問題是我不能在PHP中使用數組。我沒有得到任何錯誤或成功的消息。 在Firefox的網絡日誌中,我可以看到具有正確值的Post方法。將jQueryUI對話框中的變量發送到AJAX的PHP對話框

繼承人的我的js代碼片段:

<script> 
    // open popup window "dialog" 
     $(function() { 
      $("#dialog").dialog({ 
       autoOpen: false , 
       width: 1000, 
       buttons: { 
        "Quelle hinzufügen": function() {       

         var out = [document.getElementById("titelin"),document.getElementById("autorin"),document.getElementById("tagsin"),document.getElementById("linkin")]; 
         var outv = [out[0].value,out[1].value,out[2].value,out[3].value];      
         ajax(outv); 
        }, 
       Abbrechen: function() { 
        $(this).dialog("close"); 
       } 
       } 
      }); 
      $("#opener").click(function(e) { 
       e.preventDefault(); 
       $("#dialog").dialog("open"); 
      }); 
     }); 
     // posting to PHP 
     function ajax(outv){ 

      $.ajax({ 
       type:"POST", 
       url:"quellenverzeichnis.php", 
       data: {output: outv},    
       sucess: function(){ 
        alert("works"); 
       }, 
       error: function(){ 
        alert("fail"); 
       } 
      }); 
     }; 
    </script> 

繼承人我的PHP代碼:

<?php 

if (isset($_POST['output'])){ 
    hinzufuegen(); 
}; 
printf($_POST['output']); 

?> 

鴕鳥政策知道我做錯了,對不起我的英文不好和德語單詞在代碼中。 感謝您的幫助

+0

'數據:{輸出:BLA}'這哪裏是喇嘛到來從? – vinayakj

+0

那爲什麼你的請求空白,因爲未定義'bla'不會發送'output'字段 – vinayakj

+0

printf($ _ Post ['output']);是錯誤的,你應該使用printf($ _ POST ['output']); – talsibony

回答

0

使用下面的代碼片段

  buttons: { 
       "Quelle hinzufügen": function() { 
       var out = []; 
       out.push(document.getElementById("titelin").value); 
       out.push(document.getElementById("autorin").value); 
       out.push(document.getElementById("tagsin").value); 
       out.push(document.getElementById("linkin").value); 
       ajax(out); 
     }, 

而且

 function ajax(info){ 

      $.ajax({ 
       type:"POST", 
       url:"quellenverzeichnis.php", 
       data: {output: info},     
       success: function(data){ 
        alert("works"+data); 
       }, 
       error: function(){ 
        alert("fail"); 
       } 
      }); 
     }; 

而且

 $_POST['output'] 
+0

感謝您的幫助它工作.. 。但我的問題是,我期望在網站上打印,但它確定像 –

+0

你嘗試回聲?我已經更新了代碼,現在試試 – vinayakj

+0

sucess消息不彈出,但我得到的數組在php中,可以做sql請求 –