php - jQuery Ajax 发布到 php 没有捕获变量

标签 php javascript jquery ajax post

我做错了什么。 PHP 似乎无法从 $.ajax 捕获 titlewrapper。代码看起来是否正确。我收到的成功消息指示未找到标题的错误。

jQuery 主.html

$.ajax({
   type: "POST",
   url: "process.php",
   data: 'title=test&wrapper=testing',
   success: function(msg){
     alert( "Data Saved: " + msg );
   } 
});

PHP 进程.php

<?php 
$title = $_REQUEST['title'];
$wrapper = $_REQUEST['wrapper'];
...
?>

最佳答案

看看:jQuery.ajax()

数据参数最好是键/值对对象,它更干净,更容易调试:)

$.ajax({
   type: "POST",
   url: "process.php",
   data: {
     title: 'test',
     wrapper: 'testing'
     },
   success: function(msg){
     alert( "Data Saved: " + msg );
   } 
});

关于php - jQuery Ajax 发布到 php 没有捕获变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6517445/

相关文章:

php - 将字符串从 xml 插入 mysql 可以工作,但有时会导致 PDOException : SQLSTATE[42000]: Syntax error or access violation: 1064

javascript - 所有的 JavaScript 回调都是异步的吗?如果不是,我怎么知道哪些是?

javascript - 用一些东西代替 <span> 以有效的方式包裹 <ul>

javascript - 在子 div 中滚动(固定)应该滚动父 div

javascript - fullPage.js - 多张幻灯片中的背景视频

javascript - 如果浏览器是 Chrome,我怎样才能在这个 jQuery 脚本中有不同的行为?

php - 试图从 PHP 执行用 C 编译的文件

php - MySQL 服务器已消失 - 恰好在 60 秒内

javascript - 为什么ajax无法将数据返回到表td中的元素?

javascript - JSON 对象和字符串函数