javascript - jQuery - $.ajax returns other dataFormat as $post -


When I get data from server $ If I use Ajax, the format looks different than the $ .post request result. How can I change the $ .post request to get the same format with a $ .ajax request? Otherwise I can not use my loop to read the data:

Working code with $ ajax:

  $ .ajax ({url: "/ fetchdata. Php ", type:" post ", data type:" jason ", data:" param = no ", success: work (data) {console.log (data); for (var i = 0; i & lt ; Data; lanf; i ++) {$ ('# dom'). ('& Lt; li & gt;' + data [i] .username '' ;);} }, Error: task (e) {console.log (e);}});  

Console $ .get result:

  [object, object, object, object]  

no Work Code with $ Post:

  var jqxhr = $ .post ("/fetchdata.php", function (data) {console.log (data); for (var i = 0 ; & Lt; li & gt; '+ data [i] .username' '');}}) .done (function) (
  • () { }. .file (function () {}) .ways (function () {}); $ .post result in console:
      [{"id_usesrs": "1", " Username ":" A "}, {" "4", "Username": "D": "2", "Username": "B"}, {"id_usesrs": "3" "Name": "c"}, {"id_usesrs"}]  
  • Specify that it returns to JSON and not the string

    $. ("/ Fetchdata.php", function {data} {...}, 'json')

    The last parameter is $ .post () dataType is equal to $. Ajax ()

    More info


    Comments

    Popular posts from this blog

    java - Can't add JTree to JPanel of a JInternalFrame -

    javascript - data.match(var) not working it seems -

    javascript - How can I pause a jQuery .each() loop, while waiting for user input? -