Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

make jquery to wait for .get function

Posted on 2011-09-09
5
Medium Priority
?
569 Views
Last Modified: 2012-05-12
Hello.

I have this function
function runAjaxCap(mycode) {
	//$("#captchacatcher")
	var xaa='';
	xaa='parser3.php?code='+mycode;	
	jQuery.get(xaa,function(fileContents){jQuery("#captchacatcher").html(fileContents);});

}

Open in new window


I need to wait until
jQuery.get(xaa,function(fileContents){jQuery("#captchacatcher").html

Open in new window

has change my div content.

Please HELP.
Thanks
0
Comment
Question by:radugheorghies
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36513815
use $.ajax (or use jQuery.ajaxSetup) to make a synchrone ajax call :

function runAjaxCap(mycode) {
	//$("#captchacatcher")
	var xaa='';
	xaa='parser3.php?code='+mycode;	
	var fileContents = jQuery.ajax({ "url":xaa "async":false }).responseText;
        jQuery("#captchacatcher").html(fileContents); 
}

Open in new window


more info : http://arshadinfo.wordpress.com/2008/05/25/what-is-the-difference-between-asynchronous-ajax-and-synchronous-request/
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 36513838
try:
function runAjaxCap(mycode) {
//force it to wait for get completion
jQuery.ajaxSetup({async:false});
	//$("#captchacatcher")
	var xaa='';
	xaa='parser3.php?code='+mycode;	
	jQuery.get(xaa,function(fileContents){jQuery("#captchacatcher").html(fileContents);});

//restore default so it won't "break/interfere" with other ajax calls
jQuery.ajaxSetup({async:true});

}

Open in new window

0
 

Author Comment

by:radugheorghies
ID: 36513863
Sorry leakim971

something is wrong here:
var fileContents = jQuery.ajax({ "url":xaa "async":false }).responseText;

thanks for answering.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36513877
add a comma after xaa

var fileContents = jQuery.ajax({ "url":xaa, "async":false }).responseText;
0
 

Author Closing Comment

by:radugheorghies
ID: 36513883
Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question