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.

    评论

报告相同问题?