Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6619685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:00:03+00:00 2026-05-25T21:00:03+00:00

If I set type to ‘GET’ in the code below it works, but I

  • 0

If I set type to ‘GET’ in the code below it works, but I cant get it to work with ‘POST’.

ajaxPostTest.html…

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script type="text/javascript">

$(document).ready(function(){

    $.ajax({
        url: "ajaxPostTest_server.php",
        data: {"fruit1": "rasp", "fruit2": "bramble"},
        type: 'POST',
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function(data){
            $("#returned").append(data.fruit1);
            },
        error: function(jqXHR, textStatus, errorThrown){
             alert("error") ;
            }
        });
});

</script>
</head>
<body>
<div id="returned">returned: </div>
</body>
</html>

ajaxPostTest_server.php…

<?php
    echo json_encode($_REQUEST);
?>

The expected output on the browser is…

returned: rasp

I’m actually attempting to interact with an ASP.NET web server and I want to confirm my ajax is working (and I understand ajax properly) first – hence this simplified code.

Firebug debugging…

Response Headersview source
Date    Fri, 23 Sep 2011 14:57:37 GMT
Server  Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By    PHP/5.3.1
Keep-Alive  timeout=5, max=99
Connection  Keep-Alive
Transfer-Encoding   chunked
Content-Type    text/html
Request Headersview source
Host    localhost
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18
Accept  application/json, text/javascript, */*; q=0.01
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Content-Type    application/json; charset=utf-8
X-Requested-With    XMLHttpRequest
Referer http://localhost/My_Webs/temp/ajaxPostText1.html
Content-Length  26
Cookie  PHPSESSID=mgvoacnluh3kad5pakafrd5kd1

All I get in the ‘response’ tab is…

{"PHPSESSID":"mgvoacnluh3kad5pakafrd5kd1"}

I.e. I cant find where the data I send to the server is going to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:00:04+00:00Added an answer on May 25, 2026 at 9:00 pm

    Because your sending your data as “application/json”, PHP does not populate $_POST / $_REQUEST. You need to send the request as “application/x-www-form-urlencoded” (you can leave out the “Content-Type” parameter because this is the default type).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to set the default style for a type in code-behind e.g. for: <ScaleTransform
At the moment we set content-type in our responce headers, a bit like this...
I created a project in flex builder with application server type set to none.
I have your run of the mill nested set hierarchy type setup with the
I have a products table with a column of type SET (called especialidad), with
I'm trying to set the group type for a new Active Directory Entry via
I want to install a set of Open Type Fonts as part of my
I have a mysql table field set as time type which stores data in
In Visual Studio 2008 project properties, Application tab, I can set the Output type
Set<Type> union = new HashSet<Type>(s1); union.addAll(s2); AND Set <Type> union = new HashSet<Type>(); union.addAll(s1);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.