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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:53:38+00:00 2026-05-21T01:53:38+00:00

I am sending a json string using JQuery.ajax to a php page where I

  • 0

I am sending a json string using JQuery.ajax to a php page where I am trying to pull the array and mediate through the variables. For some reason, I can see the POST in firebug when I run the script but I when I attempt to get the parameters all I get is an empty Array(). I have been trying to figure this out for hours and am at my wits end. I moving from asp.net to .php so I am still a little fresh with my syntax, but this seems like it should be fairly simple.

Here is my code for the jquery send.

$('#form_add').submit(function() {
    var serial_data = $(this).serialize();
    $(".page_content").fadeOut("slow", function(){
        $.get(uri_base +'/'+uri_cont+'/get_db_name/true/'+Math.random(), function(data) { 
            $.ajax({
                type: 'POST',
                url: uri_base +'/AJAX/add_record/'+data+'/'+Math.random(),
                data: serial_data,
                contentType: "application/json",
                success: function(data){
                    $.ajax({
                        type: 'POST',
                        url: uri_base +"/"+ uri_cont +"/"+ uri_func,
                        data: data,
                        success: function(data){
                            alert(data)


                        },
                        error: function(xhr, ajaxOptions, thrownError){
                             alert(xhr.status);
                             alert(thrownError);
                        }

                    });  

                },
                error: function(xhr, ajaxOptions, thrownError){
                     alert(xhr.status);
                     alert(thrownError);
                }

            });

        });                       
    });
    return false;
});

Ignore the first .get(), that just pulls back a variable to complete the next URL. The first.ajax() call sends the serialized form data to my AJAX controller and pushes into the db. The return from the controller sends back an Array of Objects that I converted to json.

if(isset($key)){    
    $data['add_msg'] = $this->model_ajax->add_record($table,$array);
    $exploded_data = json_encode($data['add_msg']);
    print_r($exploded_data);
    exit;
}

From there the next .ajax() is supposed to send the data to my controller to pull back a view to display in the .pag_content div. I have tried echoing the json object, a for each loop to pull the keys out, and a myriad of other things. nothing … I get either a JSON Invalid error (when trying to decode it), Just “Array()” output, or nothing at all when looping through them.

This is the controller code and the POST output that I am seeing in firebug…

echo $_POST;

$array = $_POST;
echo $array;

foreach($_POST as $key){
    echo $key;
}
exit;

[{"id":"29","datetime":"2011-03-23 12:10:25","full_name":"Leroy Brown","email_address":"test@testing.com","password":"asdf","id_group":"0","id_sites":"0","active":"0"}]
  • 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-21T01:53:38+00:00Added an answer on May 21, 2026 at 1:53 am

    before you output anything in php make sure you send the right content-type. The frameworks like JQuery and mootools tend to filter (as they should) with Accept charsets (you can see that in firebug)

    header(“Content-Type: application/json”);
    // could also be text/json, check the accept headers in firebug depending on your framework

    🙂

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

Sidebar

Related Questions

I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
The data I am sending my page is encoded in JSON, parsed using Javascript
I am trying to receive a json object back from php after sending data
I'm using jquery to send a json string to an ASMX web service. The
I am sending a json object from java to php. I am using gson
I am sending a json string from my iphone application to server using ASIFormDataRequest.
I am new to Javascript and Jquery. I am using Jquery $.ajax for sending
I am using JQuery 1.5.1. Sending JSON data (encoded using https://github.com/douglascrockford/JSON-js ) to the
I have an app that uses ajax (jQuery) quite extensively and when sending JSON
I am having an issue trying to post a JSON string using dojo.xhrPost to

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.