...">

Problems with HTML in IE

I wrote html login code as follwing

<div id="wrapper"> <div id="page"> <div class="aLogin"> <label>User Name : </label> <input type="text" class="lname" /> <label>Password : </label> <input type="password" class="lpwd" /> <input type="submit" class="logSubmit" value="LOGIN" /> <p class="lalert">test alert</p> </div> </div> 

and wrote jQuery for validation. It will replace the warning (here I used <p class="lalert">test alert</p> ) dynamically.
The problem is that when I run this in IE, a warning was issued twice. But in other browsers there are no problems.

jQuery

 $(document).ready(function(){ $('.logSubmit').click(function(){ var name = $('.lname').val(); var pwd = $('.lpwd').val(); $.post("/login.php",{name:name,pwd:pwd}).success(function(data){ var obj = jQuery.parseJSON(data); $('.lalert').fadeIn('slow'); if(obj.success == 1){ $('.lalert').css('color','#067800'); $('.lname').val(''); $('.pwd').val(''); $('.lalert').html(obj.msg); }else{ $('.lalert').css('color','#CC0000'); $('.lalert').html(obj.msg); } }); }); }); 

login.php

  <?php $name = $_POST['name']; $pwd = $_POST['pwd']; $err['success'] = 0; $err['msg'] = ''; if($name != 'admin'){ $err['msg'] = 'Invalid Name'; }else if($pwd != 'admin'){ $err['msg'] = 'Invalid Password'; }else{ $err['success'] = 1; $err['msg'] = 'Success'; } echo json_encode($err); ?> 

I can’t understand why this is happening. Can someone help me ..?

+7
source share
4 answers

Finally, I got a solution. The problem is due to the Node Blank Text . IE8 generates blank Node text for line breaks after the <input>,<select>,<img> tags.

I removed these spaces after the tags and now the problem is resolved.

0
source

Hi. You forgot to write "return false".

 $('.logSubmit').click(function(){ var name = $('.lname').val(); var pwd = $('.lpwd').val(); $.post("/login.php",{name:name,pwd:pwd}).success(function(data){ var obj = jQuery.parseJSON(data); $('.lalert').fadeIn('slow'); if(obj.success == 1){ $('.lalert').css('color','#067800'); $('.lname').val(''); $('.pwd').val(''); $('.lalert').html(obj.msg); }else{ $('.lalert').css('color','#CC0000'); $('.lalert').html(obj.msg); } }); return false; }); 
+1
source

try using instead of $('.logSubmit').click(function(){ ...}

use the syntax below

 $('.logSubmit').unbind('click').click(function(){ .....} 

this can solve the problem.

0
source

Try adding return false; into your .logSubmit -click-linker. In addition, you can try replacing the input with the <β†’ button since the views are related to forms (submission), and this is not the case in your situation.

0
source

All Articles