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"}}].
2
  • try to log you response in console then see your response data Commented Feb 15, 2019 at 9:46
  • Kurtis@console data is @@@ 0: Balanceledger: {id: "2", username: "rawat", amount: "100", reason: "wdeadeses", requestid: "0", …} proto: Object Commented Feb 15, 2019 at 9:49

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

5 Comments

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
try the second one then or refer to the following answer stackoverflow.com/a/9997087/5225589
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
Ahmad Khundaqji@you there?
var formattedJson = JSON.stringify(result, null, '\t');@this is working but this return json array. while i want print only database result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.