点击< i>标签生成一个新的散列(不会工作) [英] Clicking a <i> tag to generate a new hash (won't work)

查看:161
本文介绍了点击< i>标签生成一个新的散列(不会工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,这只是使< span> 中的文本为空。当你点击< i> 标签时,它会产生一个新的散列到< span> / code>标签。



HTML:

 < p class =reg-code>哈希值:< span><?php echo $ hash; >< / span>< i class =fa fa-refresharia-hidden =trueid =refresh-hash>< / i>< / p> 

AJAX:
点击(函数(){
$ .post(../api/register_hash.php,函数(数据) ){
$(.reg-code> span).html(data);
});
});

PHP:

  $ num = rand(0,10000); 
$ hash = password_hash($ num,PASSWORD_BCRYPT,array(
'cost'=> 6
));


解决方案

($ _ POST ['action'] =='get_hash'){

 #查找动作词
{
$ num = rand(0,10000);
$ hash = password_hash($ num,PASSWORD_BCRYPT,array(
'cost'=> 6
));
#Die(echo here)
die($ hash);
}

我不知道应该在< i id =refresh-hash> 块,但没有什么可点击的,< i> 是空。我添加了REFRESH这个词,因此有点点击。

 < p class =reg-code> Hash:< span><?php echo $ hash?>< / span>< i class =fa fa-refresharia-hidden =trueid =refresh-hash> REFRESH< / I>< / p为H. 

< script>
$(document).ready(function(){
//在这里尝试使用on()
$('#refresh-hash')。on('click',function (){
//发送数据(动作词)
//同时确保../api/register_hash.php实际上是
//正确路径
$ .post(../ api / register_hash.php,{action:'get_hash'},函数(data){
console.log(data);
$(。reg (数据);
});
});
});
< / script>

如果您想知道,我确实检查过它,如果执行得当,它确实有效。可能你的主要问题是你没有在PHP方面回应( die($ hash); )。


For some reason this just makes the text in the <span> blank. I'm trying to make it so when you click on the <i> tag, it generates a new hash into the <span> tag.

HTML:

<p class="reg-code">Hash: <span><?php echo $hash; ?></span><i class="fa fa-refresh" aria-hidden="true" id="refresh-hash"></i></p>

AJAX:

$('#refresh-hash').click(function(){
  $.post( "../api/register_hash.php", function(data) {
    $(".reg-code > span").html(data);
  });
}); 

PHP:

$num = rand(0, 10000);
$hash = password_hash($num, PASSWORD_BCRYPT, array(
    'cost' => 6
));

解决方案

A couple things you can do to make things work:

# Look for an action word
if($_POST['action'] == 'get_hash') {
    $num = rand(0, 10000);
    $hash = password_hash($num, PASSWORD_BCRYPT, array(
        'cost' => 6
    ));
    # Die (echo here)
    die($hash);
}

I don't know what is supposed to be in your <i id="refresh-hash"> block, but there is nothing there to click, the <i> is empty. I added the word "REFRESH" so there was something to click.

<p class="reg-code">Hash: <span><?php echo $hash ?></span><i class="fa fa-refresh" aria-hidden="true" id="refresh-hash">REFRESH</i></p>

<script>
$(document).ready(function() {
    // Try using "on()" here
    $('#refresh-hash').on('click',function(){
        // Send data (action word)
        // Also make sure the "../api/register_hash.php" is actually the
        // correct path
        $.post("../api/register_hash.php", {"action":'get_hash'},function(data) {
            console.log(data);
            $(".reg-code > span").html(data);
        });
    });
});
</script>

In case you are wondering, I did check this and it does work if properly implemented. Likely your main problem is that you are not echoing the return on the php side (die($hash);).

这篇关于点击&lt; i&gt;标签生成一个新的散列(不会工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆