将数据从jQuery.post返回给PHP时未定义的参数

I am trying to return data from a database and populate a text field after the user enters an ID in the first text box. Currently I had the code working as long as the user did not enter a space in the ID number. Now I am attempting to allow that use case. My PHP code returns a json encoded array with three fields: first_name, last_name, and full_name.

When I use console.log(data) to view the data being returned I receive the following:

    {"first_name":"Test","last_name":"Test","full_name":"Test Test"} 

However in my code, I try to write data.full_name in a .val() nothing is populated, and when use the console.log I get an error saying "undefined".

Here is the whole jQuery Code:

    $("#ID").blur(function () {
        var params = {};
        params.ID = encodeURIComponent($(this).val());
        $.post("getter.php", params, function ( data ) {
          if (!data) {
             $("input[name=username]").val("User Not Found");
          } else {
             $("input[name=username]").val(data.full_name);
             $("input[name=username]").attr("readonly", true);
          }
        });
     });

Any help you can offer would be much appreciated.

Force jQuery to read the returned data as json:

$("#ID").blur(function () {
        var params = {};
        params.ID = encodeURIComponent($(this).val());
        $.post("getter.php", params, function ( data ) {
          if (!data) {
             $("input[name=username]").val("User Not Found");
          } else {
             $("input[name=username]").val(data.full_name);
             $("input[name=username]").attr("readonly", true);
          }
        }, "json"); // <- json forced
     });

and then make sure your returned data is in proper json format (for example with json_encode in php)

Use trim() to remove spaces.

Then you can check if the parameter value is_numeric(), and if false, set a default value.