使用jQuery AJAX调用将数据传递给函数

我试图在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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法在 jquery 中使用 Ajax 将数据传递给 php 函数

jQuery将Ajax调用中的数据传递给MVC操作方法

Ajax JQuery将数据传递给POST方法

将多个表单数据传递给jquery函数

如何使用 ajax .post() 将数据传递给 php

如何使用php将mysql数据库数据传递给javascript函数?

Laravel使用Ajax将数据传递给控制器

使用Ajax加载模型时将数据传递给Bootstrap模型

使用Ajax将表单数据传递给PHP的问题

如何使用ajax正确地将数据传递给php?

将未使用的数据传递给python函数:性能损失吗?

不使用构造函数将StatefulWidget数据传递给State类

jQuery AJAX POST 不将数据传递给 PHP 脚本

Ajax jquery(post)不将数据传递给php

将整个表单作为数据传递到jQuery Ajax函数中

使用 setresult() 将数据传递给活动

Swift - 使用字典将数据传递给参数

使用javascript将数据传递给模态

使用模式时将数据传递给UIViewController

使用HTML表单将数据传递给Javascript代码

使用 CollectionViewCell _Swift 将 Firebase 数据传递给 DetailView

使用jQuery触发事件将数据传递给Change事件处理程序?

如何使用javascript或jquery在不重新加载的情况下将数据传递给标题

jQuery 将数据属性传递给函数

使用Ajax将数据传递到PHP文件

如何使用Codeigniter将数据传递到Ajax中?

无法使用AJAX将数据传递到php文件

如何使用ajax将数据传递到php?

使用Jquery $ .ajax将json数据传递到servlet(doPost)