View previous topic :: View next topic |
Author |
Message |
hassan68 Smarty Rookie
Joined: 27 Apr 2011 Posts: 21
|
Posted: Mon May 21, 2012 9:02 am Post subject: smarty & ajax |
|
|
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"> 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(' <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 |
|
hassan68 Smarty Rookie
Joined: 27 Apr 2011 Posts: 21
|
Posted: Tue May 22, 2012 10:20 am Post subject: |
|
|
no reply
no support |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Tue May 22, 2012 10:43 am Post subject: |
|
|
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 |
|
hassan68 Smarty Rookie
Joined: 27 Apr 2011 Posts: 21
|
Posted: Tue May 22, 2012 2:43 pm Post subject: |
|
|
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 |
|
hassan68 Smarty Rookie
Joined: 27 Apr 2011 Posts: 21
|
Posted: Tue May 22, 2012 7:48 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue May 22, 2012 7:57 pm Post subject: |
|
|
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 |
|
hassan68 Smarty Rookie
Joined: 27 Apr 2011 Posts: 21
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 24, 2012 1:30 pm Post subject: |
|
|
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 |
|
|