weixin_33726313 2014-06-06 11:41 采纳率: 0%
浏览 19

关于ajax php和json

MY ajax code looks like this:

jQuery(document).ready(function($) {

$(".respond").submit(function(event){
  ..................//something here
    request = $.ajax({
        url: "/admin/check.php",
        type: "post",
        data: {formData:serializedData,submit_type:submit_name},
        datetype: JSON
    });
    request.done(function (response, textStatus, jqXHR){
        console.log(response);
    });
    request.fail(function (jqXHR, textStatus, errorThrown){
        console.error(
            "The following error occured: "+
            textStatus, errorThrown
        );
    });
    request.always(function () {
        $inputs.prop("disabled", false);
    });
    event.preventDefault();
});
});

And when i use php code like this

var_dump($_POST["formData"]);

It gives result like this

"string(400) "user_edit=submit&user_id=1 ..........
"

I want to store userid in php variable like this

$username=......

But when i try doing like this

$username=$_POST["formData"]["userid"] 

it gives error

"
Warning: Illegal string offset 'user_edit' in C:\Program Files (x86)\Ampps\www\admin\check.php on line 5
string(1) "u" "

I want to know how to i get the value of that userid or something like that.

  • 写回答

3条回答 默认 最新

  • weixin_33709219 2014-06-06 11:45
    关注

    As you see when dumping formData, it is a string! You want to access an element of it as it was an array -> error.

    A better approach could be to include 'submit_type' in your form and just have

    data: serialisedFormData 
    

    as your post data.

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R