2

Am new to jquery.I need to know how to pass external json file as a argument to a function.

I know how to pass as a object in client side like below.

var json = { "key": "value" }

Basically i need to call this below function by passing the json data.

function draw(json) {
 // Code here

  console.log(json);

}

In client side json means i know to how to pass.

draw(json);

But my json file is come from server(External Json File)

I tried jquery.getJson() method also.But not getting exact solution.I don't know what i did mistake also.

My $.getJson code

draw("$.getJSON("http://localhost/cb/json/Json_30647.json",function(data) {

      return data;   

    }));

Please help me to solve this issue.Thanks in advance.

user3824494
  • 101
  • 2
  • 9

1 Answers1

4

You can not return from an asynchronous method. You are trying to eat the pizza before it it delivered to your house.

Call the function when the call is complete:

$.getJSON("http://localhost/cb/json/Json_30647.json",function(data) {
      draw(data);   
});
epascarello
  • 204,599
  • 20
  • 195
  • 236