我试图在AJAX中回调函数PHP。但这对我不起作用,是否正确下面的代码?任何帮助,我将不胜感激,谢谢!
JavaScript AJAX调用
//AJAX call for button
$("#primaryTextButton").kendoButton();
var button = $("#primaryTextButton").data("kendoButton");
button.bind("click", function(e) {
var test = $("#dropdown").val()
$.ajax({
url: "../DesignationProgramTemplate/testjson.php",
type: "POST",
data: function(){
return {
method: "getAddTemplate",
}
},
success: function (respond) {
// you will get response from your php page (what you echo or print)
kendo.alert('Success'); // alert notification
},
});
});
PHP函数(testjson.php)
function addTemplate(){
global $ehorsObj;
$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$hrsPositionID = (isset($_POST['id']) ? $_POST['id'] : '');
$programID = (isset($_POST['progid']) ? $_POST['progid'] : '');
// $id = $_POST['id'];
// $progid = $_POST['progid'];
for($x=0; $x< sizeof($progid); $x++ )
{
$array = array();
$sqlSelect = "SELECT * FROM tblHrsPositionProgramTemplate WHERE hrsPositionID = '".$id."'
AND programID = '".$progid[$x]."'";
$GetResult = $ehorsObj->FetchData($sqlSelect, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
$positionTemplateID = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplate");
$sqlAdd = "INSERT IGNORE INTO tblHrsPositionProgramTemplate
SET positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW() ,
active = 'y' ";
$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
$positionTemplateIDLog = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplateLog");
$sqlAddLog = "INSERT IGNORE INTO tblHrsPositionProgramTemplateLog
SET positionTemplateIDLog = '" . $positionTemplateIDLog . "',
positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW(),
active = 'y' ";
$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}}
我想将函数addTemplate调用到AJAX调用中。如何将方法称为“ getAddTemplate”。我真的很想知道是否有任何代码是错误的。或者我想念一些东西。谢谢!
这是解决我的问题的答案。希望可以帮助别人!
$.ajax({
type: "POST",
url: "../DesignationProgramTemplate/testjson.php",
data: {
method: "deleteTemplate" ,
id: test,
progid: array
},
// data: {'id':test,'progid':array},
success: function(){
kendo.alert("Data updated");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句