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

x
?
Solved

jQuery .POST not posting results on html

Posted on 2011-02-19
10
Medium Priority
?
386 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 2000 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

688 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