Javascript функция

tu6o

Registered
Създавам следната функция:

Код:
function checkIt(index){

	$.ajax({
					type: "POST",
					url: "somefile.php",
					data: "check="+index,
					success: function(msg){

					if (msg=="no")
					return false;
					
					else return true;
					
					}
				});


}

Трябва този return да е за функцията checkIt(), а не за success: function(). Какво не е наред?
 
tu6o каза:
Създавам следната функция:

Код:
var result;
function checkIt(index){

	$.ajax({
					type: "POST",
					url: "somefile.php",
					data: "check="+index,
					success: function(msg){

					if (msg=="no") {
					result false;
					}
					else { result = true; }
					
					}
				});
return result;


}

Трябва този return да е за функцията checkIt(), а не за success: function(). Какво не е наред?
Пробвай нещо такова
 
Код:
	 function checkIt(index){

   $.ajax({
               type: "POST",
               url: "somefile.php",
               data: "check="+index,
            });

               success: function(msg){
               if (msg=="no")
               return false;
               else return true;
               }

}


така?
 
embaka каза:
Код:
	 function checkIt(index){

   $.ajax({
               type: "POST",
               url: "somefile.php",
               data: "check="+index,
            });

               success: function(msg){
               if (msg=="no")
               return false;
               else return true;
               }

}

Няма как да работи, дори има syntax error на този ред:
success: function(msg){
 
Пробвай така

var result;
function checkIt(index){

$.ajax({
type: "POST",
url: "somefile.php",
data: "check="+index,
success: function(msg){

if (msg=="yes") {
result true;
}
else { result = false; }

}
});
return result;


}
 
baso каза:
Пробвай така

var result;
function checkIt(index){

$.ajax({
type: "POST",
url: "somefile.php",
data: "check="+index,
success: function(msg){

if (msg=="yes") {
result true;
}
else { result = false; }

}
});
return result;


}

Пробвах и не работи може би защото му трябва време, за да получи отговор от php скрипта.
 
А така?

var result;
function checkIt(index){

$.ajax({
type: "POST",
url: "somefile.php",
data: "check="+index,
success: function(msg){

if (msg=="no") {
result false;
}
else { result = true; }

}
});
result return;


}
 
Благодаря ти много, няколко дни си блъсках главата и така и не намерих отговор. :?:
 

Back
Горе