Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing php array to script via jquery.get()
    primarykey
    data
    text
    <p>in my script, i have this line..</p> <pre><code>$scope.items = [{"id":"1","name":"name 1","description":"description 1","field3":"field3 1","field4":"field4 1","field5 ":"field5 1"}]; </code></pre> <p>i made a data.php file to simulate the array value of $scope.items shown above</p> <pre><code>&lt;?php getaccessories = array("id"=&gt;"1","name"=&gt;"name 1","description"=&gt;"description 1","field3"=&gt;"field3 1","field4"=&gt;"field4 1","field5 "=&gt;"field5 1"); echo json_encode($getaccessories); ?&gt; </code></pre> <p>the idea is to receive this array from data.php to $scope.items in my script via jquery.get(). i tried below statement with no result. how will it be done?</p> <pre><code>$scope.items = $.get("data.php", function(data){}, "json"); </code></pre> <p>@sergiu, here's what you have asked me to do for data.php, please see if i did it right?</p> <pre><code>&lt;?php // $getaccessories = array("id"=&gt;"1","name"=&gt;"name 1","description"=&gt;"description 1","field3"=&gt;"field3 1","field4"=&gt;"field4 1","field5 "=&gt;"field5 1"); $getaccessories = array(); $accessory = new stdClass(); $accessory-&gt;id = "1"; $accessory-&gt;name = "name 1"; $accessory-&gt;description = "description 1"; $accessory-&gt;field3 = "field3 1"; $accessory-&gt;field4 = "field4 1"; $accessory-&gt;field5 = "field5 1"; $getaccessories[] = $accessory; echo json_encode($getaccessories); ?&gt; </code></pre> <p>------ EDIT for Sergiu ------</p> <p>this is the output of chrome's console.log with the original value of $scope.items</p> <pre><code>[Object] 0: Object age: 50 name: "Moroni" __proto__: Object length: 1 __proto__: Array[0] </code></pre> <p>and here's $scope.items with $.get()</p> <pre><code>Object {readyState: 1, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…} $$v: Array[1] 0: Object age: 50 name: "Moroni" __proto__: Object length: 1 __proto__: Array[0] </code></pre> <p>i'm hope this helps</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