and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi
I need to send id to script and return array..
I have my first_page.php
Here I have try this
[syntax="javascript"]$.get('log.php',{id:'4'},function(data){
alert("Data Loaded: " + data);
});
log.php receive id..
Now, i need GET into first_page.php a result as js array..
How I must prepare this data in log.php and how I can get this on first page ?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I think the word you're looking for is JSON. json.org maintains a list of available JSON libraries (scroll to bottom of page). I used Services_JSON for this purpose (after ripping it out of the class to a simple function).
var mycontacts = new Array();
$.getJSON("log.php",{id: "5"}, function(ps){
for (var i = 0; i < ps.length; i++)
{
mycontacts[i] = new Array('ps[0].idd', 'ps[1].email', 'ps[2].nome','ps[3].idg');
}
});
var mycontacts = new Array();
$.getJSON("log.php",{id: "5"}, function(ps){
for (var i = 0; i < ps.length; i++)
{
mycontacts[i] = new Array('ps[0].idd', 'ps[1].email', 'ps[2].nome','ps[3].idg');
}
});
var mycontacts = new Array();
$.getJSON("log.php",{id: 5}, function(ps){
for (var u = 0; u < ps.length; u++)
{
mycontacts[u] = new Array(ps[u].idd, ps[u].email, ps[u].nome, ps[u].idg);
console.log(mycontacts[u][1]);
}
});
console.log(mycontacts);
the first console output is OK
the second, out of function and $.getJSON result nothing: [ ]
?
seems that var is empty after function.. but is global
var mycontacts = new Array();
$.getJSON("log.php",{id: 5}, function(ps){
for (var u = 0; u < ps.length; u++)
{
mycontacts[u] = new Array(ps[u].idd, ps[u].email, ps[u].nome, ps[u].idg);
console.log(mycontacts[u][1]);
}
});
console.log(mycontacts);
the first console output is OK
the second, out of function and $.getJSON result nothing: [ ]
?
seems that var is empty after function.. but is global
Nb. var is defined before
help pls
I'm going to assume that you didn't read the json.org page that was posted earlier...
If your php file is returning a json string you will need to either use a json parser (read the site) or use eval() to turn the json data into the javascript variable it represents...