Solved

jQuery .POST not posting results on html

Posted on 2011-02-19
10
384 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
[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
  • 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
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 

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
 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…
Suggested Courses

617 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