Solved

jQuery .POST not posting results on html

Posted on 2011-02-19
10
378 Views
Last Modified: 2012-05-11
I don't see what I am doing wrong.

Here is the code
$("#EntireMenu a").live('click',function(){
					
				//$('.divPage:last').remove();
					var myObj = $(this);
				
				switch ($(this).attr('class')){
					case 'mReports':
						$('.divPage:first').fadeOut(50, function(){
								$(this).remove();
						});
						$("<div/>", {
				      "id": "RepPage",
				      "class":"divPage1",
															}).hide().appendTo("#body"); 
						$.ajax({
										type:"POST",
										url:'/aaMain/reports.php',
										data:{repType: myObj.attr('href').split('#')[1]
											},
										dataType:'json',
										success:function(responseText){
												// handle response
												alert('we got somethn!');
												$('#RepPage').html(responseText, function(){
														$('#RepPage').show();
													});
											}
									});
						
						//alert ('we got class - mReports!');
						var width_div = $('.divPage table').width() ? $('.divPage table').width() :1200;
						
		    		$('#footer').css({'position':'absolute','top':'500', 'width':width_div});
		      	$('#footer').fadeIn();
		      	// get data
		      	
						return false;
						break;

Open in new window


the switch continues.... but the code that is not working is what is above.

In firebug I can see more of what is going on , but I still don't understand why it shows the html in firebug but not on my page see attached image.
jQuery-POST.png
0
Comment
Question by:gbeaulac
  • 6
  • 4
10 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34935508
Try an synchrone ajax call, so replace your current ajax call by the following :


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

Open in new window

0
 

Author Comment

by:gbeaulac
ID: 34935575
It spits out the alert, but still does not show the html.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34935584
do you get your html code in the alert with the following ?
var rt = $.ajax({type:"POST",url:'/aaMain/reports.php',data:{repType: myObj.attr('href').split('#')[1]},dataType:'json',"async":false}).responseText;
alert(rt);
$('#RepPage').html(rt);
$('#RepPage').show();

Open in new window

0
 

Author Comment

by:gbeaulac
ID: 34935595
YES!

I removed the alert and now we have display!

But can you also tell me what was wrong with my code? Why it would not work?
0
 

Author Closing Comment

by:gbeaulac
ID: 34935600
This is the second time you have helped me. I am grateful.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:gbeaulac
ID: 34935606
When I make a second choice from my menu, it does not display until I reclick the menu. Any reason for that?
0
 

Author Comment

by:gbeaulac
ID: 34935618

I was reading your code and just clued in (even though you mentioned it in your first answer) that we are not going async. Isn't that defeating the purpose of using ajax?
I am sure you have a good reason, don't get me wrong, but I was wondering if you could explain why that is, please?

Sorry about the tons of questions...
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34936966
>When I make a second choice from my menu, it does not display until I reclick the menu. Any reason for that?
>I was reading your code and just clued in (even though you mentioned it in your first answer) that we are not going async. Isn't that defeating the purpose of using ajax?

I was thinking we need to wait the data before continue the switch
With an async ajax call the program don't wait the end of the call and continue. So if you're doing thing thinking the data is available, it's not the case, for example moving a div of changing style attibute of object not available (before the end of the ajax call)

generaly you can use a async ajax call (generaly) but you need to have control of all what happen in the code.
0
 

Author Comment

by:gbeaulac
ID: 34937819
ok Thank you
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34937821
np, have a nice sunday !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

929 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

8 Experts available now in Live!

Get 1:1 Help Now