I have the following PHP script:
我有以下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!
Telefonnummer existiert bereits!"); // Not successful
}
break;
Now I'd like to save selected rows from a jqGrid with the PHP script above. Here is the code of the grid and a custom button:
现在我想用上面的PHP脚本从jqGrid保存选定的行。这是网格的代码和自定义按钮:
$("#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("
Bitte eine Adresse auswählen!
");$("#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: // ???
});
}
}})
I need to post the operation mode "ManAdd" (oper = "ManAdd") and the address to the server. In this case which datatype is needed and how is the data option constructed?
我需要将操作模式“ManAdd”(oper =“ManAdd”)和地址发布到服务器。在这种情况下,需要哪种数据类型以及如何构造数据选项?
1 个解决方案
#1
1
It seems to me that it would be enough to set no dataType and to use as the data parameter something like following:
在我看来,设置没有dataType并用作数据参数就足够了,如下所示:
data: {oper: 'ManAdd', Name: NameLine, Address: AddressLine, PLZ: ZipCode,
Ort: City, TelNr: PhoneNumber}