0

Hi I am trying to fetch data on same page through ajax.But not success.when I am using html(result) to print success message it's not working .But when I used .text(result) its working but return [object],[object] Here is my ajax code.

$(document).ready(function(){
    $('#frm_rechargeHistory_process').submit(function(){
        var username = $("#username").val();
        var dataString = 'username='+ username;
        if(username==''){
            alert("Please Fill All Fields");
        }else{
        // AJAX Code To Submit Form.
            $.ajax({
              type: "POST",
              url: "getfoundhistory",
              data: dataString,
              cache: false,
              success: function(result){
                  alert(result);
                  $('#txtHint').html(result);
              }
            });
        }
    return false;
    });
});

While Browser Network response is perfect

 [{"Balanceledger": {"id":"2","username":"rawat","amount":"100","reason":"wdeadeses","requestid":"0","approveid":"0","created_date":"2018-11-19 10:41:03"}}].
Kalaiselvan
  • 2,095
  • 1
  • 18
  • 31
sanjay yadav
  • 95
  • 10

1 Answers1

0

From what you are posting the response is coming in the format of JSON. and this needs to be reconstructed in a way that is represented as TEXT or in best cases HTML format

try something like this before replacing the HTML contents

var tmpData = JSON.parse(result);
var formattedJson = JSON.stringify(result, null, '\t');
Ahmad Khundaqji
  • 332
  • 2
  • 12
  • Ahmad Khundaqji@can you post exact code with question .. I am getting JSON.parse(result) error . please let me know what will be exact code – sanjay yadav Feb 15 '19 at 09:53
  • try the second one then or refer to the following answer https://stackoverflow.com/a/9997087/5225589 – Ahmad Khundaqji Feb 15 '19 at 09:55
  • Ahmad Khundaqji@data return like that [ { "Balanceledger": { "id": "2", "username": "rawat", "amount": "100", "reason": "wdeadeses", "requestid": "0", "approveid": "0", "created_date": "2018-11-19 10:41:03" }] but I need only data row not json – sanjay yadav Feb 15 '19 at 09:59
  • Ahmad Khundaqji@you there? – sanjay yadav Feb 15 '19 at 10:01
  • var formattedJson = JSON.stringify(result, null, '\t');@this is working but this return json array. while i want print only database result – sanjay yadav Feb 15 '19 at 10:08