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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:58:06+00:00 2026-06-05T06:58:06+00:00

I try to pass array using jquery by ajax and back but my code

  • 0

I try to pass array using jquery by ajax and back but my code not working well.
I all the time change it but it is not working.
please advise what to do.
I think my jquery code is ok but php code not replay.
thx.

html code.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript" >
$(document).ready(function(){
    var allVals = { 
              'a': '1', 
              'b': '2',
              'c': '3' 
            }; 
            //$.each(allVals, function(key, value) { 
              //alert(key + ': ' + value); 
                //  });
            });
$.ajax({
    type: "POST",
     dataType: 'html',
     url: "test4.php",
     data: 'allVals=' + allVals,
         cache: false,
         success: function(data)
         {
            alert(data);
            $('#test').html(data);
            }
         });
</script>

<title>Insert title here</title>
</head>
<body>
<div id="test">##</div>
</body>
</html>

php code test4.php

<?php
    $allVals = $_POST['allVals'];
    if ($allVals != ""){
          foreach ($allVals as $key => $value) {
          echo ($key.' '.$value."<br />");
    }     }

?>
  • 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-05T06:58:08+00:00Added an answer on June 5, 2026 at 6:58 am

    You can also send an array to PHP from jQuery like this. In your example your sending an object:

    <?php 
    if($_SERVER['REQUEST_METHOD']=='POST'){
        header('Content-Type: text/html');
        print_r($_POST['allVals']);
        /*
        Array ( [0] => 1 [1] => 2 [2] => 3 ) 
        */
        die;
    }
    ?>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
    $(function() {
    
        var myJavascriptArray = new Array('1', '2', '3');
        //or var myJavascriptArray=["1","2","3"]; 
    
        $.ajax({
            type: "POST",
            dataType: 'html',
            url: "test.php",
            data: {'allVals[]=' : myJavascriptArray},
            cache: false,
            success: function(data){
                $('#test').html(data);
            }
        });
    
    });
    </script>
    
    </head>
    
    <body>
    <div id="test"></div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to pass variable from jquery to code c# but something is wrong.
I'm working on a program where I try to pass parameters by reference. I'm
I am using jQuery and PHP. I have a JavaScript array , when I
I am using PHP + jQuery AJAX to log a user into my site.
I am using cakephp and trying to pass an array from the view to
I'm trying out this basic authentication using jQuery. But nothing happens when I enter
I'm trying to pass an array from a jQuery function to my controller. The
I want to pass some data around threads but want to refrain from using
I'm using hidden forms to pass variables between pages (using POST). It's working fine
What is the difference between ',' and 'as' in except statements, eg: try: pass

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.