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 8987215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:44:08+00:00 2026-06-15T21:44:08+00:00

I’m successfully making an AJAX call with the Jquery $.ajax method, in that the

  • 0

I’m successfully making an AJAX call with the Jquery $.ajax method, in that the file it’s POSTing to is getting called and executing. However, no POST data is being sent. All I want to do is send the data and have it received by the file; I don’t care about returning data.

I’ve tried changing it to GET, which didn’t yield results. I passed GET data in the URL which was received (obviously, I guess). I’ve also tried changing the data type that I’m sending…none of this has given me any ideas as to what I’m doing wrong. I’ve also browsed the numerous questions here with similar titles, but nothing seemed to fix this issue. Though I’m sure it’s something simple.

Other variables that may be relevant: I’m using Knockout JS. I’m using .htaccess redirects to create a single point of entry in a /public folder.

And without further ado, here’s the code:

page.html

<button data-bind="click: save">Save</button>

If you’re unfamiliar with KOJS, it basically just calls the function save when you click it. I’m pretty sure this is working properly.

models.js

self.save = function() {
    var jsonData = ko.toJSON(self.tasks);
    $.ajax("http://test.local.com/js/post.php", {
        data: jsonData,
        type: "post", contentType: "application/json",
        success: function(result) { alert(jsonData) }
    });
};

That alert is giving me a nicely formatted JSON object, like

[{"title": "Clean up the dog"},{"title": "Warm up the old pasta"}]

It’s the post file, I think, where my error is? The $_POST array is empty. And if I change it to send as GET, that’s also empty. I put comments in the code explaining things.

post.php

if (isset($_POST)) {
  //It does get inside this if. That's good at least, right?

  $my_file = 'file.txt';
  $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
  //It will make this file.

  fwrite($handle, print_r($_POST));
  //Prints "1" without the quotes


  foreach ($_POST as $key => $value) {
    fwrite($handle, 'your data: '.$value.'; ');
  }
  //Prints nothing
}

Any thoughts as to why this won’t send any POST data? I’m sure it’s something silly. Thanks!

  • 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-06-15T21:44:09+00:00Added an answer on June 15, 2026 at 9:44 pm

    Your issue is that you’re setting data as a JSON string. Per the docs jQuery won’t process string data, only objects http://api.jquery.com/jQuery.ajax/

    Instead use ko.toJS to get a clean JS object and that should get you going in the right path.

    [edit]

    I just noticed you were setting the contentType as well… For that to work you won’t be able to use the $_POST var. Instead you’ll need to grab the data from file_get_contents("php://input") that “should” give you the raw JSON string. From there you should be able to use PHP’s json_decode to turn it into a true PHP object.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.