使用jQuery $就调用PHP函数

编程入门 行业动态 更新时间:2024-10-26 18:29:05
本文介绍了使用jQuery $就调用PHP函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这可能是一个简单的答案,但我使用jQuery的$就调用PHP脚本。我想要做的基本上是把那PHP脚本函数内调用从JavaScript的PHP函数。

This may be a simple answer, but I'm using jquery's $.ajax to call a PHP script. What i want to do is basically put that PHP script inside a function and call the PHP function from javascript.

<?php if(isset($_POST['something'] { //do something } ?>

<?php function test() { if(isset($_POST['something'] { //do something. } } ?>

我如何将调用的JavaScript函数?现在,我只是用$就与列出的PHP文件。

How would i call that function in javascript? Right now i'm just using $.ajax with the PHP file listed.

推荐答案

使用 $。阿贾克斯来调用服务器环境(或URL,或其他)来调用特定的'行动'。你需要的是这样的:

Use $.ajax to call a server context (or URL, or whatever) to invoke a particular 'action'. What you want is something like:

$.ajax({ url: '/my/site', data: {action: 'test'}, type: 'post', success: function(output) { alert(output); } });

在服务器端,动作 POST参数应阅读和相应的值应该指向方法来调用,例如:

On the server side, the action POST parameter should be read and the corresponding value should point to the method to invoke, e.g.:

if(isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; switch($action) { case 'test' : test();break; case 'blah' : blah();break; // ...etc... } }

我相信这就是 Command模式简单的化身。

更多推荐

使用jQuery $就调用PHP函数

本文发布于:2023-11-23 10:22:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   jQuery   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!