douju6651 2014-06-08 14:53
浏览 55

如何从JQuery AJAX调用PHP类方法

I have created user registration form and pass that values to class successfully. I want to know how to save that data using jquery ajax. but I don't know the way to call php class via jquery ajax. my code is this:

<?php
 if(isset($_POST['register'])){
    $register = new Users();
    $msg = $register->registration($_POST['fullname'], $_POST['email'], $_POST['phone'], $_POST['password'], $_FILES);
}

?>
<h3> Registration </h3>

<?php
    if(isset($msg)){
        echo $msg;
    }
?>
<form action="" method="post" enctype="multipart/form-data">
    <p> Full name: <input type="text" name="fullname"/> </p>
    <p> Email: <input type="email" name="email"/> </p>
    <p> Phone: <input type="phone" name="phone"/> </p>
    <p> Password: <input type="password" name="password"/> </p>
    <p> Photo 1: <input type="file" name="photo[]"/> </p>
    <p> Photo 2: <input type="file" name="photo[]"/> </p>
    <p> <input type="submit" name="register" value="Register"/> </p>
</form>

Please someone help me to save this form using jquery ajax.

  • 写回答

1条回答 默认 最新

  • donglun2024 2014-06-08 15:10
    关注

    You will probable want something like this:

    Without a PHP framework, here are some ways to do it:

    1 - Put the function in its own file.

    2 - Put a wrapper function in its own file: all it does is #require your file, then call your desired function.

    3 - Create one file that handles ajax (that'll be the entry point). Then pass a choice of functions using GET. Something like ajax_handler.php?fn=MyFunction

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测