将数字转为字符串 php_PHP会自动将数字转换为字符串吗?

我使用dojo和ajax向

PHP发送时间戳,它执行数据库检查,然后返回时间戳以进行调试.当我发送这个时间戳时,它是一个数字,当它返回时,它是一个字符串.这有什么特别的原因吗?我该怎么做才能避免这种情况(在PHP中转换为int,通过JSON修复,或者在javascript中转换为int)

这是Dojo代码

dojo.xhrGet({

url: 'database/validateEmail.php',

handleAs: "json",

content: {

email : 'George.Hearst@Pinkerton.dw',

time: 0

},

load: function(args) {/*SEE BELOW*/}

});

这是PHP脚本

/**

** connect to the MySQL database and store the return value in $con

*

*/

$con = mysql_pconnect("localhost:port", "username", "password");

/**

** handle exceptions if we could not connect to the database

*

*/

if (!$con) {

die('Could not connect: ' . mysql_error());

}

/**

** Create table query

*

*/

mysql_select_db("portal", $con);

/**

** Get user entered e-mail

*

*/

$emailQuerry = mysql_num_rows(mysql_query("SELECT EMAIL FROM user WHERE EMAIL='" . $_GET["email"] . "'")) == 1;

/**

** Whether successful or not, we will be returning the time stampe (this is used to determine whether there were any changes between the time a request

** was sent, and when this response was returned.

*

*/

$result['time'] = $_GET["time"];

/**

** Currently only checks to see if the two values were provided. Later, will have to check against passwords

*

*/

if ($emailQuerry) {

$result['valid'] = true;

}

else {

$result['valid'] = false;

}

echo json_encode($result);

?>

最后,加载功能在上面留空了

load: function(args) {

console.log(localArgs.time + ' v ' + args.time);

console.log(localArgs.time === args.time);

console.log(localArgs.time == args.time);

}

其输出是

0 v 0

false

true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值