Solved

Why does this $.ajax work and not the other?

Posted on 2011-02-19
6
326 Views
Last Modified: 2012-05-11
Why does this code not work

$.ajax({
			type:"POST",
			url:'/aaMain/reports.php',
			data:{repType: myObj.attr('href').split('#')[1]
		},
			dataType:'json',
		success:function(responseText){
		// handle response
		$('#RepPage').html(responseText, function(){
		$('#RepPage').show();
		});
	}
});

Open in new window



BUT this code works?

var rt = $.ajax(
		{type:"POST",
		url:'/aaMain/reports.php',
		data:{repType: myObj.attr('href').split('#')[1]},
		dataType:'json',"async":false}).responseText;
		$('#RepPage').html(rt);
	        $('#RepPage').show();

Open in new window

0
Comment
Question by:gbeaulac
6 Comments
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34935908
In the first, add a hook to the error function and see if you are getting any errors.
0
 
LVL 4

Accepted Solution

by:
LAMASE earned 250 total points
ID: 34936594
Try with

async:false

Open in new window


without quotes


var rt = $.ajax(
		{type:"POST",
		url:'/aaMain/reports.php',
		data:{repType: myObj.attr('href').split('#')[1]},
		dataType:'json',async:false}).responseText;

Open in new window

0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 34936985
http://javascript.about.com/od/ajax/a/ajaxasyn.htm

the first one don't wait for the data and execture the lines of code below your ajax call (line 14 and so on...)
the second wait for the data before executing the lines of code below your ajax call  (line 6,7, and so on...)

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:LAMASE
ID: 34937450
Sorry for my previous post, i didn't understand wich one was not working:

in jQuery documentation i can't see any second parameter for html()

$('#RepPage').html(responseText, function(){
    $('#RepPage').show();
});

Open in new window


so probably this will work

$('#RepPage').html(responseText);
$('#RepPage').show();

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34937675
"async":false
is correcter than
async:false

and I am sure you can do

$('#RepPage').html(responseText).show();
0
 

Author Closing Comment

by:gbeaulac
ID: 34937947
Thank you all.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
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)

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now