Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

smarty & ajax

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
hassan68
Smarty Rookie


Joined: 27 Apr 2011
Posts: 21

PostPosted: Mon May 21, 2012 9:02 am    Post subject: smarty & ajax Reply with quote

why this code not work in header.tpl
Code:

  <script src="http://{$url}/js/jquery.js" type="text/javascript"></script>
   <script src="http://{$url}/js/settings.js" type="text/javascript"></script>
    {literal}
    <SCRIPT type="text/javascript">
pic1 = new Image(16, 16);
pic1.src = "loader.gif";

$(document).ready(function(){

$("#username").change(function() {

var usr = $("#username").val();

if(usr.length >= 3)
{
$("#status").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking availability...');

    $.ajax({ 
    type: "POST", 
    url: "check.php", 
    data: "username="+ usr, 
    success: function(msg){ 
   
   $("#status").ajaxComplete(function(event, request, settings){

   if(msg == 'OK')
   {
        $("#username").removeClass('object_error'); // if necessary
      $("#username").addClass("object_ok");
      $(this).html('&nbsp;<img src="accepted.png" align="absmiddle"> <font color="Green"> Available </font>  ');
   } 
   else 
   { 
      $("#username").removeClass('object_ok'); // if necessary
      $("#username").addClass("object_error");
      $(this).html(msg);
   } 
   
   });

 }
   
  });

}
else
   {
   $("#status").html('<font color="red">The username should have at least <strong>3</strong> characters.</font>');
   $("#username").removeClass('object_ok'); // if necessary
   $("#username").addClass("object_error");
   }

});

});

//-->
</SCRIPT>
 {/literal}

this code dont have any action in my form
Back to top
View user's profile Send private message
hassan68
Smarty Rookie


Joined: 27 Apr 2011
Posts: 21

PostPosted: Tue May 22, 2012 10:20 am    Post subject: Reply with quote

no reply
no support
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue May 22, 2012 10:43 am    Post subject: Reply with quote

hassan68 wrote:
no reply
no support


It's been 26hours since your post. Your Post did not contain any error messages or descriptions of what's happening. You did not describe what is not working the way you expect it to work. Are the people on this board supposed to guess what you want?

From what I can see your smarty template looks fine. I have not looked into your javascript.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
hassan68
Smarty Rookie


Joined: 27 Apr 2011
Posts: 21

PostPosted: Tue May 22, 2012 2:43 pm    Post subject: Reply with quote

rodneyrehm wrote:


It's been 26hours since your post.


for programmer 26hours is very very very long time
ok
i want to chek my database (like yahoo) for username that see this username is registered or no
but ajax dont work
why?
Back to top
View user's profile Send private message
hassan68
Smarty Rookie


Joined: 27 Apr 2011
Posts: 21

PostPosted: Tue May 22, 2012 7:48 pm    Post subject: Reply with quote

a question
how we can post with ajax just like first post ajax code
to php file
when i use that ajax code in my form
just i have
Checking availability...
and i think post not work
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue May 22, 2012 7:57 pm    Post subject: Reply with quote

smarty is ajax-agnostic. It is entirely up to your implementation to make ajax work, as well as debug it.

first, check your browser source, see that what you intended to get displayed is indeed what is getting displayed. if not, fix the template.

Then, check your javascript console for errors. check the apache log, see that ajax requests do come through.
Back to top
View user's profile Send private message Visit poster's website
hassan68
Smarty Rookie


Joined: 27 Apr 2011
Posts: 21

PostPosted: Thu May 24, 2012 8:23 am    Post subject: Reply with quote

tnx for answer mohrt
mr mohrt
can u edit for me this code that i can use it for smarty
code is in this site
http://web.enavu.com/tutorials/checking-username-availability-with-ajax-using-jquery/
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu May 24, 2012 1:30 pm    Post subject: Reply with quote

hassan68 wrote:
tnx for answer mohrt
mr mohrt
can u edit for me this code that i can use it for smarty
code is in this site
http://web.enavu.com/tutorials/checking-username-availability-with-ajax-using-jquery/


No, but it should work the same from Smarty as it does from PHP. Just make sure you escape {} tags, and check filepaths for any files that get included.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP