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

我开发了一个jQuery插件,允许你调用任何核心PHP函数甚至用户定义的PHP函数作为插件的方法:jquery.php

在我们的文档头部包含jquery和jquery.php并将request_handler.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 DOM

P.callback(false);

// Both .end() and .data return data to variables

var 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 array

var 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、付费专栏及课程。

余额充值