Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中将主文件中编写的函数调用为ajax文件&;jquery_Php_Jquery_Ajax_Function - Fatal编程技术网

如何在php中将主文件中编写的函数调用为ajax文件&;jquery

如何在php中将主文件中编写的函数调用为ajax文件&;jquery,php,jquery,ajax,function,Php,Jquery,Ajax,Function,在主文件(index.php)中编写了一个Jquery函数&希望调用从主文件调用的ajax文件中的同一函数。如果在主页面中调用该函数,并且您将ajax注入其中的容器,则该函数需要可供调用,在ajax文件的末尾添加 function()//主函数 您还可以在ajax成功后选择另一种方法,您可以直接调用函数。。。通过将其作为回调传递,例如: ajax(url,mainFunction,true) function ajax(url, callback, async) { var dat

在主文件(index.php)中编写了一个Jquery函数&希望调用从主文件调用的ajax文件中的同一函数。

如果在主页面中调用该函数,并且您将ajax注入其中的容器,则该函数需要可供调用,在ajax文件的末尾添加 function()//主函数

您还可以在ajax成功后选择另一种方法,您可以直接调用函数。。。通过将其作为回调传递,例如:

ajax(url,mainFunction,true)


function ajax(url, callback, async) {
    var date = new Date();
    var ticks = date.getTime();

    if (url.indexOf('?') == -1)
        url = url + "?tick=" + ticks;
    else
        url = url + "&tick=" + ticks;


    $.ajax({
        type: 'GET',
        url: url,
        dataType: 'html',
        async: async == undefined ? true : async,
        success: function (data) {

            if (data != undefined)
                callback(data);
        },

        error: function (xhr, textStatus, errorThrown) {
           //throw error
        },

        complete: function () {

        }

    });
}

请提供更多的细节和代码我们需要更多的上下文。我已经编写了为用户评级创建颜色的代码。它的工作很好,当写一个审查表添加相同的页面。但是,当我们添加了使用ajax编写审查表单时,set rating函数不起作用。