$.getJSON is not working!

1,155 views
Skip to first unread message

Mohamed Sekkina

unread,
Apr 30, 2011, 11:20:25 AM4/30/11
to play-framework
I have a problem with the $.getJSON function, I don't know actually
what is happening but when I call the function it works, though the
actions inside the $.getJSON function doesn't work, here's the code:

<script type="text/javascript">
function showOrganizations(user){
$.getJSON('@{BrowseController.browseOrganizations()}',
{'userName': user}, function(data){
alert("Hello!");
var orgs = data.joinedOrgs;
var orgsPart = "";
if(orgs == null || orgs == ""){
document.getElementById("joinedOrgs").innerHTML = "No organizations
to show";
} else {
var x = orgs.split("&&");
orgsPart = "";

for(var i = 0; i<x.length; i = i+1){
orgsPart += "<p> <a href = '#' onclick = \"getInsideOrg('" +
"" + user + "','" + x[i] +"')\">" + x[i]+ "</a></p>";
orgsPart += "<div id = \"org" + x[i] + "\"></div>";
}
document.getElementById("joinedOrgs").innerHTML = orgsPart;
}

orgs = data.managedOrgs;
if(orgs == null || orgs == ""){
document.getElementById("managedOrgs").innerHTML = "No organizations
to show";
} else {
var y = orgs.split("&&");
orgsPart = "";

for(var j = 0; j<y.length; j = j+1){
orgsPart += "<p> <a href = '#' onclick = \"getInsideOrg('" +
"" + user + "','" + y[j] +"')\">" + y[j]+ "</a></p>";
orgsPart += "<div id = \"org" + y[j] + "\"></div>";
}
document.getElementById("managedOrgs").innerHTML = orgsPart;
}
});
}
</script>

Pascal Voitot Dev

unread,
Apr 30, 2011, 1:11:07 PM4/30/11
to play-fr...@googlegroups.com
what do you mean with "it doesn't work"?
does it call the BrowserController.browseOrganizations() function?
does it send anything by Ajax?
do you see the alert ?

Pascal


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Steven Rigney

unread,
May 1, 2011, 9:45:09 PM5/1/11
to play-framework
$.getJSON will send GET to the server. Browsers are more likely to
cache a get, which will make it looks like the method is called, but
the browser returns the data that it has cached without actually
calling the server. If you want to ensure that it calls the server
every time, use $.ajax and set the datatype to json. http://api.jquery.com/jQuery.ajax/


Also if you are using jQuery you may as well clean up the code a
little. Instead of
document.getElementById("joinedOrgs").innerHTML = "No organizations to
show";

use
$("#joinedOrgs").html("No organizations to show");

The other getElementById calls can be cleaned up the same way.

On Apr 30, 10:20 am, Mohamed Sekkina <mohamed.sekk...@gmail.com>
wrote:

Pascal Voitot Dev

unread,
May 2, 2011, 3:00:42 AM5/2/11
to play-fr...@googlegroups.com
And use firefox plugins such as Firebug or Chrome Tools which are very very useful to see what happens exactly on the network at browser level!

Pascal

Reply all
Reply to author
Forward
0 new messages