显示数组值-ajax

I want to display the values in datatable. How to retrieve the object value in ajax success function.. ajax

AJAX

  $(function(){
  $(document).on("click", "#submits", function(e) {
  e.preventDefault();

    var password = $("#password").val();
    alert(password);
     $.ajax({
     type: "POST",
     url: "db/add.php",
     data: "password="+password,
     success: function(results){
        alert( "Data Saved: " + results );

        var obj = JSON.parse(results);
        }
});

    e.preventDefault();

});

});
</script>

Try this code :

$(results.patient_password).each(function(i,v){
   console.log(v.id);
});

Perhaps you can try this -

$("#submits").bind("click", function(e) {
    $.ajax({
        type : "POST",
        dataType : "json",
        cache : false,
        url : "db/add.php",
        data : "password="+password,
        success : function(results) {
            alert("Data Saved: "+results);
                var userInfo = JSON.parse(results);

                //Output the data to an HTML element - example...
                $(".user-name").html(userInfo.patient_name);

            }else{
                console.log('No user info found');
            }
        },
        error : function(a,b,c) {
            console.log('There was an error getting user info.');
        }
    });
});

//HTML element for data
<p class="user-name"></p>

I've added an HTML element you can simply output the data to. Not sure how you'd like the data to be output but this is simply an example.

Just some quick notes on your code from your original post -

  • You must set the dataType to json when working with/parsing json. See Documentation.
  • Once you assign your data to a variable, you need to access that data by declaring the variable and then the data name, such as obj.patient_name.

I've done the best I can to help.

Good luck.

use data-type:json,

in your jquery