如何使用jQuery在屏幕上设置值而不是使用警报?

时间:2022-05-09 14:23:43

I am using the code that I will post below. I generates the password and works fine. Only problem is that it shows me the regenerated password in the alert box. I want to echo it on the screen. how can I do that. Thanks Using jQuery fancybox and php

我正在使用我将在下面发布的代码。我生成密码,工作正常。唯一的问题是它在警告框中显示了重新生成的密码。我想在屏幕上回应它。我怎样才能做到这一点。谢谢使用jQuery fancybox和php

$.ajax({
    type: 'POST',
    url: '/processPassword.php',
    data: 'newPassword=' + password,
    success: function(success) {
        if(success == 1) {
            alert('The password has been reset. to: ' + password);
            location.href = 'mainpage.php';
        } else {
            alert('The password was not reset.');
        }
    }
});
});

function newPassword() {
        var password = "";
        some logic...
        return password;
}

2 个解决方案

#1


2  

Try this. Replace the "alert" call with the jQuery line below to set the HTML of a div...

尝试这个。用下面的jQuery行替换“alert”调用来设置div的HTML ...

HTML

<div id="newPass"></div>

jQuery

//this assumes that "password" has already been setup.
$("#newPass").html(password); 

I also would strongly advise you to consider having your PHP page generate the password and to use jQuery or something similar to request a PW to be built with server side code. Making the PW with client side code seems to be a huge security hole, almost like giving the blue prints of the * to the *ers...

我还强烈建议您考虑让您的PHP页面生成密码并使用jQuery或类似的东西来请求使用服务器端代码构建PW。使用客户端代码制作PW似乎是一个巨大的安全漏洞,几乎就像把囚犯的蓝色印记给囚犯......

#2


0  

This is something you could try

这是你可以尝试的

$.post {
   "processPassword.php",
   { newPassword: 'password' },
   function(data) {
       alert('Your new password is+'+data) ;
});

In this the data is the value echoed by the page processPassword.php not return so you must echo your new password in the end of page or somewhere.

在此,数据是页面processPassword.php回显的值不返回,因此您必须在页面末尾或某处回显新密码。

#1


2  

Try this. Replace the "alert" call with the jQuery line below to set the HTML of a div...

尝试这个。用下面的jQuery行替换“alert”调用来设置div的HTML ...

HTML

<div id="newPass"></div>

jQuery

//this assumes that "password" has already been setup.
$("#newPass").html(password); 

I also would strongly advise you to consider having your PHP page generate the password and to use jQuery or something similar to request a PW to be built with server side code. Making the PW with client side code seems to be a huge security hole, almost like giving the blue prints of the * to the *ers...

我还强烈建议您考虑让您的PHP页面生成密码并使用jQuery或类似的东西来请求使用服务器端代码构建PW。使用客户端代码制作PW似乎是一个巨大的安全漏洞,几乎就像把囚犯的蓝色印记给囚犯......

#2


0  

This is something you could try

这是你可以尝试的

$.post {
   "processPassword.php",
   { newPassword: 'password' },
   function(data) {
       alert('Your new password is+'+data) ;
});

In this the data is the value echoed by the page processPassword.php not return so you must echo your new password in the end of page or somewhere.

在此,数据是页面processPassword.php回显的值不返回,因此您必须在页面末尾或某处回显新密码。