Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery ajax不向php页面传递post数据_Javascript_Php_Html_Jquery - Fatal编程技术网

Javascript jQuery ajax不向php页面传递post数据

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', 数据类型:'

我尝试使用alert()获取post数据,其工作问题是数据没有传递到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; 
    });