weixin_33738578 2018-07-31 07:31 采纳率: 0%
浏览 36

在PHP中从Ajax传递数据

I want to pass data from ajax. Can anybody please tell me how is that possible??

Here is my index.php

   <form method="post" action="">
   <input type="text" id="class_name" name="class_name">
   <input type="hidden" name="user_id" id="user_id" value="<?=$user_id?>" />

   <button id="submit" name="submit" value="submit" type="submit"></button>
   </form>

and here is update.php

<?
    if(isset($_POST['submit'])) {

    user_id= $_POST['user_id'];
    class_name= $_POSt['class_name'];
    $date= date("M d , Y");

    $sql_ins="insert into chat set user_id='$user_id', class_name='$class_name', 
    time=now(),date='$date'";
    $sql_que=$db->db_query($sql_ins);
    }
?>

How can I pass this data into server via ajax not from action.?? What is the ajax script for that?? Thanks in advance

  • 写回答

2条回答 默认 最新

  • weixin_33671935 2018-07-31 07:44
    关注

    use jquery with ajax & call ajax function onclick of submit button

    $.ajax('URL', {
        type: 'POST',  
        data: { myData: 'formdata' },  // data to submit
        success: function (data) {
            console.log(data);
        }        
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题