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

  • Home
  • SEARCH
  • 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 3308806
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:33:55+00:00 2026-05-17T21:33:55+00:00

I am trying to decode JSON in php I sended using an ajax call

  • 0

I am trying to decode JSON in php I sended using an ajax call in javascript (jquery).

The javascript code:

    var editSchedule_data = {
        'action'            : 'editSchedule',
        'eventid'           : $('#eventid').val(),
        'pixels_per_minute' :$('#pixels_per_minute').val(),
         artists: {
            artist: []
        }
    }

    $('.artist').each(function(index) {
        var id=$(this).attr('id');
        id=id.split('_');
        editSchedule_data.artists.artist.push({
            'artistid'    : id[0],
            'stageid'     : id[1],
            'left'        : $(this).offset().left-$('.artists').offset().left,
            'width'       : $(this).width()
        });
    });

    $.ajax({
        type :   "POST",
        url  :   "callback.php",
        data :   editSchedule_data,
        dataType :   "json",
        async    :   true,
        success   :   function(json)  {
            if(json.success)  {
                showSucces(json.message);

            }
            else{
                showError(json.message);
            }
        },
        error: function(error){
            alert("An error occurred: "+error.message);
        }
    });

The php-code:

$clean = sanitize($_POST);

echo(json_encode($clean['artists']),
json_last_error());

echo(json_decode($clean['artists']),
json_last_error());

My output:
encode:

{"artist":[{"artistid":"4","stageid":"3","left":"360","width":"240"},{"artistid":"3","stageid":"4","left":"120","width":"240"},{"artistid":"1","stageid":"5","left":"120","width":"180"},{"artistid":"2","stageid":"5","left":"300","width":"120"},{"artistid":"5","stageid":"6","left":"480","width":"120"}]}
0

decode:

0

Can someone tell me how to get the decode function to work?

  • 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-17T21:33:56+00:00Added an answer on May 17, 2026 at 9:33 pm

    Why are you trying to use json_decode there? You already have the data as array in $_POST.That’s why json_decode fails and retuns NULL…it expects a properly formated string and you are passing it an array.
    If the dataType : “json” parameter confuses you, it specifies the type of the data you are expecting back from the server not the type of the data you are sending.
    You shoud simply process the data from $_POST, create your response , apply json_encode on it and echo the resulted string.

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

Sidebar

Related Questions

Hi i am trying to send Json via Ajax to PHP using Javascript. The
Im trying to decode a json string returned from flickr within my PHP code.
I am trying to decode a JSON string using json_decode() in PHP. Part of
I'm sending a JSON object to PHP using jQuery via $.ajax({ url: myURL, type:
i'm trying to send an js object to a php function using jquery.ajax .
I am trying to decode some JSON into a php array. Here's the code
I am sending a json string using JQuery.ajax to a php page where I
I'm trying to decode a JSON with jQuery. Here's what I get (for instance
could anyone here help me with php an decoding json? Im trying to decode
I'm trying to post some very simple data to a php file using jquery

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.