Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-19
6
Medium Priority
?
347 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 1000 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 83

Assisted Solution

by:leakim971
leakim971 earned 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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

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.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

783 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