开发者

jQuery Ajax post to php not catching variable

开发者 https://www.devze.com 2023-03-15 22:53 出处:网络
What am i doing wrong. PHP doesn\'t seem to catch titl开发者_如何学Pythone and wrapper from $.ajax. Does the code look correct. The success message i get indicate an error that title is not found.

What am i doing wrong. PHP doesn't seem to catch titl开发者_如何学Pythone and wrapper from $.ajax. Does the code look correct. The success message i get indicate an error that title is not found.

jQuery main.html

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

PHP process.php

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


Take a look: jQuery.ajax()

The data parameter is better to be a Key/Value pairs object, it's cleaner and easier to debug :)

$.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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号