Click here to Skip to main content
11,427,908 members (59,795 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Javascript jQuery

Im Trying to return a value from callback function with no success.

Can you see what is wrong here??:

function getval( callback ){
    jQuery.getJSON('', function(data) {
        // We can't use .return because return is a JavaScript keyword.
$(function () {
        $(document).ready(function() {
        getval( function ( value ) {
            alert( 'Do something with ' + value + ' here!' );
        } );
Here is JSFIddle link:

Thank you very much!
Posted 15-Apr-13 23:01pm
Edited 15-Apr-13 23:05pm
patel_vijay at 16-Apr-13 4:51am
You can not use simple getJSON method for cross domain call, you have to use JSONP. checkout this link
Prasad Khandekar at 16-Apr-13 5:42am
I suspect that the api you are trying to call is josnp ready.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


I have created a samll sample which you can use for testing and should help you in achieving what you are trying.
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(document).ready(function() {
function getval( callback ) {
	.done(function(data) {
function showAlert(val) {
    alert( 'Do something with ' + val + ' here!' );
ערן לוי at 16-Apr-13 7:44am
Thank you!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100