php - 使用 jquery ajax 将字符串传递给 php

标签 php jquery ajax json

我想将哈希字符串发送到我的 php 文件。但失败了,有人可以帮助我吗?

我的 JavaScript 是这样的:

var hashString = "#support_form";

$.ajax ({
   type: "POST",
   url:"index.php",
   data: hashString,
   success: function() {
      console.log("message sent!");
   }
});

和 php:

<?php
$theHash = $_POST['hashString'];
?>

我该怎么办?谢谢

最佳答案

您需要指定数据的名称/值

data: {hashString:hashString},

关于php - 使用 jquery ajax 将字符串传递给 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14221680/

相关文章:

php - 如何正确准备陈述?

php - mysql 两个日期之间的索引

jquery - 如何按 jQuery 数据表中的值查找特定行?

javascript - Axios 在单击按钮后调用时断开用户操作接下来发生的事情

javascript - 使用顺序 Promise 在 Javascript 和 jQuery 中运行一些 ajax 请求

php - 使用SPACE php mysql从下拉列表到单列插入的多个值

javascript - 如何自动刷新我的 php 聊天脚本?

jquery - Div 不会使用 jquery 显示()

javascript - 如何使用 php 和 javascript 从目录中获取文件名

针对由 Thinktecture 的 IdentityServer STS 保护的 REST 端点的 AJAX 调用