Hi,
I am new to JQuery and Ajax
I am trying to use the value returned from the Ajax call to the another Ajax call. Example:
$.ajax({
type: "POST",
url: "http://localhost/FormBuilder/index.php/forms/saveForm/",
async: false,
data: "formname="+formname+"&status="+status,
success: function(msg){
//alert( "Data Saved: " + msg);
getformid=msg;
}//success
});//ajax
$("#fb_contentarea_col1down21 div").each(function() {
alert("Form id "+getformid);//alerts me the Formid returned from the Cakephp controller side
var checked="false";
var id=$(this).attr("id");
var fsize=$("#input"+id+"").width();
var ftype=$("#input"+id+"").attr('data-attr');
var finstr=$("#instr"+id+"").text();
var fname=$("#label"+id+"").clone().html().replace(/<span.*/,'');
if($("#label"+id+"> span.req").length > 0)
{
checked="true";
}
$.ajax({
type: "POST",
async: false,
url: "http://localhost/FormBuilder/index.php/forms/saveField",
data: "sequence_no="+id+"&name="+fname+"&type="+ftype+"&size="+fsize+"&instr="+finstr+"&formid="+getformid+"&required="+checked,
success: function(msg){
//alert( "Data Saved: " + msg);
}//success
});//ajax
});//DIV
The first Ajax call returns the form ID and even alerts it correctly in the div, but the returned value in getformid is not reflected in the second ajax call. Please tell me what's going wrong.
Edit: Resolved the error. The cause is not in my Ajax calls at all its in my Cakephp controller where i return only my form id and not the form instance. I have changed and got the answer. Thanks for every one who helped.