javascript - ajax $_POST 数组丢失

标签 javascript php jquery

我使用 jquery $.post 函数发布到我的本地服务器。它正确发布,我看到 $_POST 数组内的值。但是当我在网站上在线上传相同的代码时,$_POST 返回空。不知何故,'name' var甚至没有被发送过来?我缺少什么?

这是 jquery/javascript 方面:

$("#box").keyup(function( event ) {
  //Simple test to see if it gets to the
  //file.
  $.post( "test-file.php", { name:"John"},       function() {
      alert( "success" );
    })
    .done(function(data) {
      //Checking the respones from the file
      alert( "second success: "+data );
    })
    .fail(function() {
      alert( "error" );
    })
    .always(function() {
      alert( "finished" );
  });



});

这是 test-file.php 文件的作用:

<?php

//Checking to see if I get to the
//file
echo "TEST:";

//Checking to see whats inside the post
var_dump($_POST);



?>

最佳答案

您需要编写 php 页面的 url。

如果是 www.my_url.com/test-file.php 你需要这样写:

$.post( "www.my_url.com/test-file.php", { name:"John"},       function() {
  alert( "success" );
}) .....

关于javascript - ajax $_POST 数组丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629769/

相关文章:

javascript - 介绍图片淡入后网页平滑淡入

javascript - 在 JSZip 中打包外部文件

javascript - YouTube Api V3 - Videos.update - 禁止错误

javascript - 如何在没有新标签的情况下打开 popup.html?

javascript - 如何让javascript加载另一个html文件?

php - 查询数据到phpmyadmin数据库表

php - 如何在运行时更改 sql_mode

javascript - 弹出消息框

javascript - 字符串化 HTML 中的空格导致无效表达式

javascript - Jquery Datepicker 日期格式在 Asp.net 中不起作用