Solved

small tweak help need with jquery ajax call

Posted on 2012-03-17
6
176 Views
Last Modified: 2012-03-18
while, working with my code, i am working on showing a message and hiding it after 5 seconds, but due to some reason, its is not working, i am going nuts here and its late now

here is my code snippet:

$("#updatefeedback").bind("click",function(){
            var data = $("form").serialize();
            $.post('sbtfeedback.cfm',data, function(data) {
                  $("#feedback_response").html(data).text()
            });
      });

my server-side file returns like this

<cfif len('FORM.sbname') IS 0>
    Error! Please Provide Your Name
    <cfelseif len('FORM.sbemail') IS 0>
    Error! Please Provide Your Email
    <cfelseif isDefined('FORM.sbcomments')>
    Error! Please provide Some Comments
<cfelse>
Cool! We did it
</cfif>

so minifying all tasks, i am actually returning the code rather than some kind of variable

the issue i am facing is, i am able to show a message but unable to hide it, don no why, what i m missing

Guide
0
Comment
  • 3
  • 3
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 37733585
what about :
$("#updatefeedback").bind("click",function(){
            var data = $("form").serialize();
            $.post('sbtfeedback.cfm',data, function(data) {
                  $("#feedback_response").html(data).text();
                  setTimeout(function() { $("#feedback_response").fadeOut("fast"); }, 5000);
            });
      });

Open in new window

0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 37734213
but settimeout is the better way of doing it, i was thing if we can use OnComplete or something that can help
0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 37734257
ok so i noted one things,

it just displays only one time and then it does not show up for any other message or for the same message
0
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.

 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37734656
>it just displays only one time and then it does not show up for any other message or for the same message

If you want replace .fadeIn("fast") by show();
$("#updatefeedback").bind("click",function(){
            var data = $("form").serialize();
            $.post('sbtfeedback.cfm',data, function(data) {
                  $("#feedback_response").html(data).text();
                  $("#feedback_response").fadeIn("fast");
                  setTimeout(function() { $("#feedback_response").fadeOut("fast"); }, 5000);
            });
      });

Open in new window

0
 
LVL 15

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 37734764
Thanks, Although i was looking some evnt callback method like oncomplete or onSendBefore but this worked for me for the time being, so its good

Thanks
0
 
LVL 82

Expert Comment

by:leakim971
ID: 37734783
onSendBefore is between line 2 and 3
oncomplete is on line 4

if you really need to do something inside the ajax process with jQuery.post use jquery.ajaxsetup & co : http://api.jquery.com/jQuery.ajaxSetup/
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

Suggested Solutions

Title # Comments Views Activity
jQuery Parallax 1 38
validation, if text area is typed or pasted into 2 25
jQuery not working on ELSE... why? 2 25
Removing HTML elements using javascript 4 22
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

863 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

23 Experts available now in Live!

Get 1:1 Help Now