gpt4 book ai didi

javascript - Ajax 数据元素未获取

转载 作者:行者123 更新时间:2023-12-02 16:30:44 24 4
gpt4 key购买 nike

我确信这里有一个错误:

var username  = $("#username").val();
var password = $("#password").val();
var login = $("#login").val();
var remember = $("#remember").val();
console.log(username, password, login, remember); //this shows up fine
$.ajax({
url: 'php/login.php',
//here i think
data: {username:username,password:password,login:login,remember:remember},
type: 'POST',
dataType: 'application/json',
success: function(data)
{ ....

因为当我进入我的login.php时,我在行上得到了 undefined index :

 <?php
$username = $_POST['username']; //here
$password = $_POST['password']; //here

if ($_POST['login']) //check if the submit button is pressed
{
$remember = $_POST['remember']; and here
.....

我在login.php中进一步返回:

 echo json_encode("true"); //or "false" 

在 Firebug 的响应 Pane 中:

 <br />
<b>Notice</b>: Undefined index: username in <b>C:\xampp\htdocs\www\php\login.php</b> on line <b>5</b><br />
<br />
<b>Notice</b>: Undefined index: password in <b>C:\xampp\htdocs\www\php\login.php</b> on line <b>6</b><br />
123123123<br />
<b>Notice</b>: Undefined index: login in <b>C:\xampp\htdocs\www\php\login.php</b> on line <b>8</b><br />

最佳答案

尝试使用php://input这允许您读取原始数据。由于您使用的是 application/json,因此您必须获取原始数据

关于javascript - Ajax 数据元素未获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28316405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com