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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:14:37+00:00 2026-06-07T07:14:37+00:00

I have a standard javascript ajax call where I’m setting the data: to json

  • 0

I have a standard javascript ajax call where I’m setting the data: to json data.

$.ajax({
    type: "POST",
    url: BaseUrl + "User/Login",    
    //url: BaseUrl + "User/Limit/1/2",
    data: '{"apiKey":"c7089786-7e3a-462c-a620-d85031f0c826","appIDGiven":"200","userName":"matt2","password":"pass"}',
    success: function(data){
        console.log(data);
    },
    error: function(request){
        console.log(request);
    },
});

I was trying to get the data in php $_POST["data"] this doesn’t work.
However, data: 'test={"apiKey":"c7089786-7e3a-462c-a620-d85031f0c826","appIDGiven":"200","userName":"matt2","password":"pass"}' works.

I was wondering is it possibly my framework or anything like that preventing $_POST["data"] from working or is this just not possible at all? Or is there something else I could use to get that data?

EDIT:

So the framework YII and the extension Restfullyii has a method to get the data it is using one line
return json_decode(file_get_contents(“php://input”), true);

Which is getting all the data without the need for data= or {data: However it seems to be returning an array so Im accessing my properties like $data[“userName”] where a true json object should be $data->[“userName”]. Correct me if I’m wrong on any of this am I getting array in this case because I’m really sending a json string? versus a json object?

EDIT x2:

So php is making it an assoc array because it is sending true to the json_decode..

  • 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-07T07:14:40+00:00Added an answer on June 7, 2026 at 7:14 am

    I think problem with your code is in the line where you set data: '{....}'.
    It should be in json format in order to be passed properly (though it also could be in string format but you’ll need to parse it on the server side)

    The code below should be working right:

    $.ajax({
        type: "post",
        url: BaseUrl + "User/Login",
        data: {"apiKey":"c7089786-7e3a-462c-a620-d85031f0c826","appIDGiven":"200","userName":"matt2","password":"pass"},
        success: function(data){
            console.log(data);
        },
        error: function(request){
            console.log(request);
        }
    });
    

    On the server side try: $_POST['apiKey'] $_POST['appIDGiven'] and so on.

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

Sidebar

Related Questions

An ajax request returns me a standard JSON array filled with my user's inputs.
I have a table of data which is generated dynamically with Javascript. Every few
I have a pretty standard upload form - user picks a file, then hits
I have a JavaScript widget which provides standard extension points. One of them is
I have a standard javascript object whose prototype is extended with a .start() method
I have a web form that uses a lot of JavaScript and ajax to
I have standard source code package under Linux which requires to run ./configure make
Is it possible to have standard war deployment, which can be deployed on tomcat
I've heard they have standard GUI guideline, but I can't seem to find a
I have a mobile site running with jQuery Mobile. I want to have standard

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.