Javascript jQuery ajax不向php页面传递post数据
我尝试使用alert()获取post数据,其工作问题是数据没有传递到php页面,结果总是Javascript jQuery ajax不向php页面传递post数据,javascript,php,html,jquery,Javascript,Php,Html,Jquery,我尝试使用alert()获取post数据,其工作问题是数据没有传递到php页面,结果总是{“success”:false,“result”:0} 我想要的是将密码发送到php页面,并使用password_hash()对其进行散列,然后返回结果 $('#spass')。在('submit',function()上{ var that=$(此), contents=that.serialize(); 警报(内容); $.ajax({ url:'passwordhashing.php', 数据类型:'
{“success”:false,“result”:0}
我想要的是将密码发送到php页面,并使用password_hash()对其进行散列,然后返回结果
$('#spass')。在('submit',function()上{
var that=$(此),
contents=that.serialize();
警报(内容);
$.ajax({
url:'passwordhashing.php',
数据类型:'json',
数据:目录,
成功:功能(数据){
警报(JSON.stringify(数据));
控制台日志(数据);
}
});
返回false;
});
更改密码
**这是我的php代码**
您可以测试您的数据是否确实没有传递到PHP页面
在PHP代码中,执行以下操作:echo$\u POST['YOUR_VARIABLE']
检查INSPECT_元素/网络浏览器,确保您确实将数据发送到了正确的链接。您的链接可能是相对的,因此您可能将数据发送到错误的链接
因此,尝试将整个链接放在ajax url中
$ .ajax ({
url: 'HTTP: //WHOLE_LINK_IN_HERE.COM/passwordhashing.php',
});
Ajax中的SET方法:键入:“POST”
你的php代码到底在哪里?但它向我发送的默认结果已经在php页面中,这意味着url是Ajax中的okSET方法:type:“POST”```$.Ajax({type:“POST”,url:url,data:data,success:success,dataType:dataType})```您可以使用$.post()和$.get()来代替$.ajax$.post()方法是为我而不是为帮助而工作的
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
**i used $.post() instead of using $.ajax() and it fix my problem**
$('#spass').on('submit',function(){
var that=$(this),
contents=that.serialize();
alert(contents);
$.post({
url:'passwordhashing.php',
dataType:'json',
data:contents,
success:function(data){
alert(JSON.stringify(data));
console.log(data);
}
});
return false;
});