簡體   English   中英

jQuery Ajax 發布到 php 未捕獲變量

[英]jQuery Ajax post to php not catching variable

我究竟做錯了什么。 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()

data 參數最好是 Key/Value 對 object,這樣更干凈也更容易調試:)

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

這是一個很好的解決方案。但是如果我嘗試通過網絡服務中的表單發送數據。

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

這里的標題和名稱是客戶端中的 forms 元素。但是我無法在基於 json 的 Web 服務文件中獲得發布值,比如 process.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM