1

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'];
...
?>
2
  • add print_r($_REQUEST) to see what's comming in. Also try replacing it with $_POST 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"; ?> Commented Jun 29, 2011 at 8:27

2 Answers 2

6

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 );
   } 
});
Sign up to request clarification or add additional context in comments.

4 Comments

Accoding to documentation ` It is converted to a query string, if not already a string`
true, I missed that. + for you :)
It was a comma syntax error that i overlooked. It is working now. Thanks
What version of jQuery was this for? It does not seem to work with 1.7.2. The $_REQUEST variable ends up empty.
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.