Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to display elements of json array returned from php within a loop in ajax(jquery)
    primarykey
    data
    text
    <p>Below ajax code is receiving a json array from php. Rest details i have written as comments: </p> <pre><code> $.ajax({ type: "POST", url: "dbtryout2_2.php", data: datastr, cache: false, //dataType: 'json', success: function (arrayphp) { //"arrayphp" is receiving the json array from php. //below code is working where iam displaying the array directly //This code displays the array in raw format. $(".searchby .searchlist").append(arrayphp); } }); </code></pre> <p>FRIENDS CONCENTRATE ON THIS SECTION.NOW I WILL MAKE U THE PROBLEM MORE CLEAR AND EXACT: 1)success function is having two code 2)one is uncommented and other is commnented 3)the commneted code works if i comment code "dataType: "json"", 4)but the uncommneted code does not work with the situation which the below code currently has</p> <pre><code> $.ajax({ type: "POST", url: "dbtryout2_2.php", data: datastr, dataType: "json", cache: false, success: function (arrayphp) { $.each(arrayphp, function (i, v) { alert(i + "--" + v); }); /*$(".searchby .searchlist").append(arrayphp);*/ }, error: function (xhr) { console.log(xhr.responseText); } }); </code></pre> <p>BELOW IS THE PHP CODE SNIPPET RESPONSIBLE FOR RETURNING JSON ARRAY:</p> <pre><code> $arrayphp = array(); //$result is containing the list of albums //iam one by one taking the album names and assigning it to $row //then from $element iam pushing the elements in $arrayphp //after pushing all the elements iam returning the json encoded array to ajax code. while ($row = mysql_fetch_array($result)) { $element = $row['cat_name']; array_push($arrayphp, $element); } echo json_encode($arrayphp); } </code></pre> <p>THE ARRAY RETURNED IS A LIST OF ALBUM NAMES:</p> <pre><code>["album1", "album2", "album5", "album4", "album6", "album7", "album8", "album9", "album10", "album11"] </code></pre> <p>THE EXACT ABOVE ARRAY IS GETTING RETURNED.</p> <p>WOULD ANYBODY FIGURE OUT WAT THE PROBLEM IS WITH MY CODE?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload