I am making an application using jQuery and Cakephp.
In this I use, as shown below, to get values from my controller
var getformid;
$.getJSON("http://localhost/FormBuilder/index.php/forms/getFormEntry", function(json) {
getformid=json.forms[0]["id"];
alert("Form id inside "+getformid);
});//json
alert("Form id ouside "+getformid);
In the above code, the internal warning that is inside $ .getJSON gives me the correct value as 75 But the external warning shows me an error since getformid is not defined. Why is that? Could we use getformid available outside of $ .getJSON. Please suggest me.SInce, I want to use this value to save the field ..
Edit: IF I try to use code like
var getformid;
$.getJSON("http://localhost/FormBuilder/index.php/forms/getFormEntry", myCallback);
function myCallback (json) {
getformid = json.forms[0]["id"];
// You can work with the response here
}
I get an error since myCallback is not defined. WHy so ?? Also I have to use the getformid value outside myCallback () function