What am i doing wrong. PHP doesn't seem to catch title
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'];
...
?>
What am i doing wrong. PHP doesn't seem to catch title
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'];
...
?>
Share
Improve this question
asked Jun 29, 2011 at 8:00
PinkiePinkie
10.2k22 gold badges81 silver badges124 bronze badges
2
- add print_r($_REQUEST) to see what's ming in. Also try replacing it with $_POST – Maxim Krizhanovsky Commented Jun 29, 2011 at 8:05
-
I've just checked your js code and it works. my process.php:
<?php $a = $_REQUEST['title']; $b = $_REQUEST['wrapper']; echo "title: $a, wrapper: $b"; ?>
– Kamil Commented Jun 29, 2011 at 8:27
2 Answers
Reset to default 6Take 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