Php 我应该使用encodeURI作为用户名、电子邮件和密码吗
我想将用户的三个输入从Jquery/Ajax安全地发送到PHP,下面是我的代码Php 我应该使用encodeURI作为用户名、电子邮件和密码吗,php,jquery,Php,Jquery,我想将用户的三个输入从Jquery/Ajax安全地发送到PHP,下面是我的代码 var username = encodeURI($(".username_inp").val()); var email = encodeURI($(".email_inp").val()); var pass = encodeURI($(".pass_inp").val()); var post = { "username":username
var username = encodeURI($(".username_inp").val());
var email = encodeURI($(".email_inp").val());
var pass = encodeURI($(".pass_inp").val());
var post = {
"username":username,
"email":email,
"pass":pass,
}
$.ajax({
url: 'ajax/logreg.php',
type: 'POST',
data: {post:JSON.stringify(post)},
success: function(ans){
console.log(ans);
}
})
我想知道我的代码是否正确,因为据我所知,人们只对URL使用encodeURI
。它正在将'
传递到POST。日志可以在这里找到
HTML
您不需要
encodeURI
字段,因为它们已经在POST中了body@AgamBanga但是我不能在没有它们的情况下发送“
”,因为“
是从输入@AgamBangaI的输入值进入您的输入的single@BrunoSnickers检查我是否已删除JSON.stringify
<input id ="email" />
<input id ="password" />
<input type = "button" id = "btnbtn" value = "Send Ajax">
$('#btnbtn').click(function(r) {
r.preventDefault()
var username = $("#email").val();
var email = $("#password").val();
var post = {
"username":username,
"email":email
}
$.ajax({
url: 'https://requestb.in/1jkr9w11',
type: 'POST',
data: {post:post},
success: function(ans){
console.log(ans);
}
})
})