$ _POST不起作用不提供从ajax传递的数据 [英] $_POST does not work does not give data passed from ajax

查看:123
本文介绍了$ _POST不起作用不提供从ajax传递的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要使用ajax传递给其他php页面的简单传递对象,但是尝试检索其效果不佳.给我未定义的错误.检查我的代码以得到澄清. 看到我的错误屏幕截图:

HI i want simple pass object using ajax to other php page but when trying retrieve its does not fine. Give me Undefined error. check my code to get clarification. See my error screen shot :

Edit.php

Edit.php

$('#regForm').on('submit', function (e)
{
    var serialData = $(this).serialize(), 
        s = location.search.split('='), 
        searchId = s[s.length-1];

    console.log(serialData);
    console.log(searchId);

    $.ajax({
        method:'POST', 
        url:'update.php',
        dataType:'json', 
        data:{data:serialData, id:searchId},
        success:function(jsonObj){
            console.log(jsonObj);
        }
    });
});

update.php

update.php

<?php 
    if(isset($_POST['submit'])){
        var_dump($_POST['data']);
        var_dump($_POST['id']);

        exit();

        $phpObj = json_decode($_POST['data']);
        echo json_encode($phpObj);
    } 
?>

推荐答案

问题在您的ajax调用中

problem is in your ajax call

$.ajax({
          method:'POST', 
          url:'update.php',
          dataType:'json', 
          data:{data:serialData, id:searchId},
          success:function(jsonObj){
              console.log(jsonObj);
          }
      });

它应该是type:'POST'而不是方法. 这就是为什么您的数据无法通过PHP文件获取的原因. 您的PHP代码正常.

its should be type:'POST' not a method. that's why your data not getting by PHP file there. Your PHP code is ok.

这篇关于$ _POST不起作用不提供从ajax传递的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆