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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:35:33+00:00 2026-05-14T22:35:33+00:00

On my client side I’m sending an ajax request with jQuery in the following

  • 0

On my client side I’m sending an ajax request with jQuery in the following matter:

$.post(script.php, { "var1":"something", "var2":"[1,2,3]" }, function(data) { }, "json");

On the server side, in the CodeIgniter’s controller I’m receiving the values like so:

$var1 = trim($this->input->post('var1'));
$var2 = trim($this->input->post('var2'));

My question is how do I convert the string in $var2 into a PHP array.
I tried using json_decode($var2, true) but it returns a null since “[1,2,3]” is not a legal JSON string by itself.

Also, if you believe there is a better way for me to read the values on the server-side please show me how.

Thank you.

  • 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-14T22:35:33+00:00Added an answer on May 14, 2026 at 10:35 pm

    As @Galen stated in his comment to my question, it works.
    The reason I got a null from json_decode is because it tried it with a non-array value, which requires a double ".

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

Sidebar

Related Questions

Client side sends post request to php on server side. Php returns json to
I have a client-side script written in jQuery that is sending text/xml data to
JS: The JS for client side validation of email field <script type=text/javascript src=http://code.jquery.com/jquery-latest.min.js> </script>
I'm building a client-side ajax login for Asp.Net MVC by doing jquery posts to
Getting JSON at client side via AJAX is something i am looking for in
Client side form validation becomes easiest by using jQuery. I tried all validators and
This client side script is being added to buttons in our existing codebase. It
following is my client side code , that retrieves text from server and prints.
Given: client-side javascript code (runs in browser, uses jquery etc). Currently the code is
I have enabled unobtrusive client side validation in my app, and I have (something

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.