jq 直接调用php文件_使用jQuery$.ajax调用PHP函数

慕雪9262066

我开发了一个jQuery插件,允许您调用任何核心PHP函数,甚至用户定义的PHP函数作为插件的方法:jquery.php在文档头中包含jQuery和jquery.php并将requesthandler.php放在服务器上之后,我们将以下面描述的方式开始使用该插件。为了便于使用,请以一种简单的方式引用该功能:    var P = $.fn.php;然后初始化插件:P('init', {

    // The path to our function request handler is absolutely required

    'path': 'http://www.YourDomain.com/jqueryphp/request_handler.php',

    // Synchronous requests are required for method chaining functionality

    'async': false,

    // List any user defined functions in the manner prescribed here

            // There must be user defined functions with these same names in your PHP

    'userFunctions': {

        languageFunctions: 'someFunc1 someFunc2'

    }});现在有一些使用场景:// Suspend callback mode so we don't work with the DOMP.callback(false);// Both .end() and .data return data to variablesvar strLenA = P.

strlen('some string').end();var strLenB = P.strlen('another string').end();var totalStrLen = strLenA + strLenB;console.log( totalStrLen );

 // 25// .data Returns data in an arrayvar data1 = P.crypt("Some Crypt String").data();console.log( data1 );

  // ["$1$Tk1b01rk$shTKSqDslatUSRV3WdlnI/"]演示PHP函数链接:var data1 = P.strtoupper("u,p,p,e,r,c,a,s,e").strstr([], "C,A,S,E").explode(",", [], 2).data();var data2 = P.strtoupper("u,p,p,e,r,c,a,s,e").

strstr([], "C,A,S,E").explode(",", [], 2).end();console.log( data1, data2 );演示如何发送PHP伪代码的JSON块:var data1 = 

        P.block({

    $str: "Let's use PHP's file_get_contents()!",

    $opts: 

    [

        {

            http: {

                method: "GET",

                header: "Accept-language: en\r\n" +

                        "Cookie: foo=bar\r\n"

            }

        }

    ],

    $context: 

    {

        stream_context_create: ['$opts']

    },

    $contents: 

    {

        file_get_contents: ['http://www.github.com/', false, '$context']

    },

    $html: 

    {

        htmlentities: ['$contents']

    }}).data();

    console.log( data1 );后端配置提供了一个白名单,因此可以限制可以调用哪些函数。还有其他一些使用PHP的模式,这些模式也是由插件描述的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值