Home > Backend Development > PHP Tutorial > 请问php传给js的变量怎么无法判断

请问php传给js的变量怎么无法判断

WBOY
Release: 2016-06-23 14:09:20
Original
1187 people have browsed it

使用了ajax的回调函数,当php传来的值=1时 js  alert 成功 传来的是2时候  js alert 失败
但是在回调函数判断msg=1 时候 无论传来是什么值 js都是alert 失败

<?php   require("mysql.php"); $name=$_POST["name"]; $password = $_POST["password"]; if(empty($name)||empty($password)){ echo"系统检测到非法登录"; } $sql="select name,password from testuser where name='$name' and password='$password'";$result=mysql_query($sql);$rows=mysql_num_rows($result);if($rows==1){echo "1";}else{echo "2";} ?>
Copy after login


js.......................

$(document).ready(function(){$("#login").bind("mouseover",login);function login(){var name = $("#username").val();var password = $("#password").val();var param = {"name":name,"password":password};if(name==""){alert("警告!非法访问,用户名为空") ;return false;}else{if(password==""){alert("警告!非法访问,密码为空")return false;}else{$.ajax({type:"post",url:"http://localhost/kkc/login.php",data:param,success:function(msg){if(msg==1){alert ("成功");}else{alert("失败");}}});}};};});
Copy after login


回复讨论(解决方案)

应该是 BOM 头的影响

echo base64_encode(file_get_contents('http://localhost/kkc/login.php'));
贴出结果

这个楼主先用chrome检查一下PHP文件返回的是什么,看看是不是有什么其他的问题

echo base64_encode(file_get_contents('http://localhost/kkc/login.php'));
贴出结果 那请问怎么如何解决啊...没碰到过这个问题...

你还没有按我要求的去做!
我如何给你下一步的建议?

难道要我糊弄你一下???

你还没有按我要求的去做!
我如何给你下一步的建议?

难道要我糊弄你一下???

bom头我已经去掉了,接下来怎么做...我是做java的  第一次做php不懂...

不是还有 require("mysql.php"); 吗?
mysql.php 的 BOM 头也去掉了吗?

是做java的 不是挡箭牌,因为那是基础知识

不是还有 require("mysql.php"); 吗?
mysql.php 的 BOM 头也去掉了吗?

是做java的 不是挡箭牌,因为那是基础知识
好吧,但是在j2ee项目中没有出现过此类问题

success:function(msg){
   alert(msg);  //看看弹出什么
if(msg==1){
alert ("成功");
}else{
alert("失败");
}

success:function(msg){
   alert(msg);  //看看弹出什么
if(msg==1){
alert ("成功");
}else{
alert("失败");
}
如果账户正确弹出1  失败弹出2

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template