Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-19
6
Medium Priority
?
343 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
[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
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 82

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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
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

670 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