简体   繁体   English

jQuery Ajax 发布到 php 未捕获变量

[英]jQuery Ajax post to php not catching variable

What am i doing wrong.我究竟做错了什么。 PHP doesn't seem to catch title and wrapper from $.ajax. PHP 似乎没有从 $.ajax 捕获titlewrapper Does the code look correct.代码看起来是否正确。 The success message i get indicate an error that title is not found.我收到的成功消息指示未找到标题的错误。

jQuery main.html jQuery 主.html

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

PHP process.php PHP 进程.php

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

Take a look: jQuery.ajax()看一下: jQuery.ajax()

The data parameter is better to be a Key/Value pairs object, it's cleaner and easier to debug:) data 参数最好是 Key/Value 对 object,这样更干净也更容易调试:)

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

Thats a good solution.but if I try to send data through a form in a webservice.这是一个很好的解决方案。但是如果我尝试通过网络服务中的表单发送数据。

$.ajax({
   type: "POST",
   url: "process.php",
   data: {
     title: $('#title').val,
     name: $('#name').val
     },
   success: function(data){
     alert(data );
   } 
});

Here title and name are forms element in client side.but i am not able to get post value in json based webservice file say process.php这里的标题和名称是客户端中的 forms 元素。但是我无法在基于 json 的 Web 服务文件中获得发布值,比如 process.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM