Solved

jQuery .POST not posting results on html

Posted on 2011-02-19
10
382 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
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!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…

710 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