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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:52:42+00:00 2026-05-26T17:52:42+00:00

I would like to send a list of data by ajax. So I push

  • 0

I would like to send a list of data by ajax. So I push all data in a 2d array

But the ajax of jquery not accept the array data, the data must be object or query string

since the Object of javascript is no push function, I must use array to build the list of data.
Is there any function in jquery or javascript, let me

var countLine=$("line").length;
var lines=$("line");
var lineArr=new Array();
var linesArr=new Array();
var x1, y1, x2, y2;
for(i=0; i<countLine; i++)
{
    lineArr['x1']=lines[i].getAttributeNS(null, "x1");
    lineArr['y1']=lines[i].getAttributeNS(null, "y1");
    lineArr['x2']=lines[i].getAttributeNS(null, "x2");
    lineArr['y2']=lines[i].getAttributeNS(null, "y2");
    linesArr.push(lineArr);
}
$.ajax({
    type: "POST",
    url: "test.php",
    data: linesArr,

    async: true,
    cache: false,

    success: function(data){
        $("#txt").text(data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown){
        alert("fail");
    }
});
  • 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-26T17:52:43+00:00Added an answer on May 26, 2026 at 5:52 pm

    Change

    data: linesArr
    

    to

    data: { linesArr: linesArr }
    

    This will send an object with a single property, "linesArr", which contains the value of your array.


    EDIT: you have a bigger problem. You are trying to store non-numeric properties in an array, as shown in this line:

    lineArr['x1']=lines[i].getAttributeNS(null, "x1");
    

    You are also reusing the same lineArr “array” each time through the loop. The following code would work much better:

    var lines = $("line");
    var linesArray = [];
    
    for (var i = 0; i < lines.length; ++i) {
        var line = lines[i];
    
        linesArray.push({
            x1: line.getAttributeNS(null, "x1"),
            y1: line.getAttributeNS(null, "y1"),
            x2: line.getAttributeNS(null, "x2"),
            y2: line.getAttributeNS(null, "y2")
        });
    }
    

    Then you would access your data like $_POST["linesArr"][0]["x1"].

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

Sidebar

Related Questions

When I send a list of int's with jQuery like this: $.ajax('@Url.Action(Execute)', { type:
I would like to send a list of Appointment s through WCF. My Interface
I would like to send a javascript array to be processed by a method
I would like to send out an update of my apk, but i did
I have a list of numbers that i would like to send out onto
I would like to send data from a server to a client, continuously (streaming),
My Django application has 10,000 users, all with emails. I would like to send
I would like to send the message from HelloWorldLayer, and receive it in ScoreLayer,
I would like to send a html string with a GET request like this
I would like to send and receive OpenSoundControl in an AIR application, on the

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.