2010-07-26 86 views
0

我有以下的PHP腳本:自定義「添加數據」 - 如何將數據發佈到PHP服務器?

$OperMode = $_POST['oper']; 
switch($OperMode) { 
/* [...] */ 
case 'ManAdd': 
      // get data 
      $Firma = $_POST['Name']; 
      $Adresse = $_POST['Address']; 
      $PLZ = $_POST['PLZ']; 
      $Ort = $_POST['Ort']; 
      $TelNr = $_POST['TelNr']; 
      /* [...] */ 
      // save data to SQL database with adapted strings 
      $Insert ="INSERT INTO adresse (Nachname, Vorname, Strasse, Hausnummer, Postleitzahl, Ort, Telefonnummer) VALUES('$Nachname', '$Vorname', '$Strasse', '$Hausnummer', '$PLZ', '$Ort', '$TelNr')"; 
      if(mysql_query($Insert)) { 
       echo "Eintrag erfolgreich."; // Successful 
      } else { 
       die("Eintrag nicht erfolgreich!<br>Telefonnummer existiert bereits!"); // Not successful 
      }    
      break; 

現在我想從jqGrid的保存選中的行與上面的PHP腳本。 這裏是網格的代碼和一個自定義按鈕:

$("#ResultGrid") 
       .jqGrid({ 
        colNames:['Firma', 'Adresse', 'Postleitzahl', 'Ort', 'Telefonnummer'], 
        colModel:[ 
        {name:'Firma', index:'Firma', width:175, searchable:false}, 
        {name:'Adresse', index:'Adresse', width:160, searchable:false}, 
        {name:'Postleitzahl', index:'Postleitzahl', width:100, searchable:false, sorttype:'int'}, 
        {name:'Ort', index:'Ort', width:150, searchable:false}, 
        {name:'Telefonnummer', index:'Telefonnummer', width:160, searchable:false} 
        ], 
        datatype: "clientSide", 
        editurl:'Edit.php', 
        height: 'auto', 
        loadonce: true, 
        multiselect: true, 
        pager:'#ResultPager', 
        rownum:-1, 
       }) 
       .navGrid('#ResultPager', {view:false, edit:false, add:false, del:false, search:false, refresh:false}) 
       .navButtonAdd('#ResultPager', {title:"Adresse ins Addressbuch übernehmen", buttonicon:"ui-icon-disk", caption:"Speichern", onClickButton:function(){ 
        if($("#ResultGrid").getGridParam('selrow') == null || $("#ResultGrid").getGridParam('selrow') == undefined) { 
         $("#Dialog").html("<p><span class=\"ui-icon ui-icon-info\" style=\"float:left; margin:0 7px 20px 0;\"></span>Bitte eine Adresse ausw&auml;hlen!</p>"); 
         $("#Dialog").dialog("option", "title", "Hinweis:"); 
         $("#Dialog").dialog("open"); 
        } else { 
         var ID = $("#ResultGrid").getGridParam('selrow'); 
         var AddressRow = $("#ResultGrid").getRowData(ID);      
         // The data to be stored: 
         var NameLine = AddressRow.Firma; 
         var AddressLine = AddressRow.Adresse; 
         var ZipCode = AddressRow.Postleitzahl; 
         var City = AddressRow.Ort; 
         var PhoneNumber = AddressRow.Telefonnummer; 

         $.ajax({ 
        type: 'POST', 
        url: 'Edit.php', 
        dataType: // ??? 
        data: // ???      
         });     
        } 
       }}) 

我需要發佈的操作模式「ManAdd」(OPER =「ManAdd」)和地址到服務器。 在這種情況下,需要哪種數據類型以及如何構造數據選項?

回答

1

在我看來,這將是足以使任何dataType並作爲data參數類似以下用途:

data: {oper: 'ManAdd', Name: NameLine, Address: AddressLine, PLZ: ZipCode, 
     Ort: City, TelNr: PhoneNumber} 
+0

非常感謝! – Laurenz 2010-07-26 12:28:36

相關問題