Click here to Skip to main content
13,258,269 members (38,965 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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
Updated 15-Apr-13 23:05pm
patel_vijay 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 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!' );

ערן לוי 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2017
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