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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:52:56+00:00 2026-05-14T20:52:56+00:00

I have a bit of a conundrum. I have a form which has numerous

  • 0

I have a bit of a conundrum. I have a form which has numerous fields. There is one field for links where you enter a link, click an add button, and the link(using jQuery) gets added to a link_array. I want this array to be sent via the jQuery.ajax method when the form is submitted. If I send the link_array using $.ajax like this:

    $.ajax({
        type: "POST",
        url: "add_stock",
        dataType: "json",
        data: { "links": link_array }
        });

when the add link button is selected the data goes no problem to the correct place and gets put in the db correctly. If I bind the above function to the submit form button using $(#stock_form).submit(….. then the rest of the form data is sent but not the link_array.

I can obviously pass the link array back into a hidden field in HTML but then I’d have to unpack the array into comma separate values and break the comma-separated string apart in PHP. It just seems 100X easier to unpack the Javascript array in PHP without an other fuss.

So, how is it that you can send an array from javascript using $.ajax concurrent to the rest of the $_POST data in HTML?

Please note that I’m using Kohana 3.0 framework but really that shouldn’t make a difference, what I want to do is add this js array to the $_POST array that is already going.

Thanks!

  • 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-14T20:52:56+00:00Added an answer on May 14, 2026 at 8:52 pm

    If you actually want to submit the form (e.g., with page refresh and all that), your only option is to add a series of <input type='hidden'> fields to the form with the name links and fill each of them with one of the values from the array. Then what you get at the other end will be essentially what you get with your $.ajax call above.

    If you just want to send the data to the server but you don’t actually need to submit the form, you can use serialize on the form to get a URL-encoded string for it, then append your links to the end of the string, and send that via ajax. Something like this:

    // Assuming 'link_array' is present
    var data, n;
    
    data = [$('#TheFormID').serialize()];
    for (n = 0; n < link_array.length; ++n) {
        data.push("links=" + encodeURIComponent(link_array[n]));
    }
    
    $.ajax({
        type: "POST",
        url: "add_stock",
        dataType: "json",
        data: data.join("&")
    });
    

    We get the beginning of the URL-encoded string from serialize, initialize an array with it, then push encoded fields for each link on it. Then we use Array#join to collect that all into one string to send with the ajax call. (You could do this with string concat instead if you like, but building these long strings with an array is faster after a certain number of elements, and makes the whole “do I put an & on it or not” just fall out naturally as well.)

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

Sidebar

Related Questions

If there is any multithreaded c# utility is there, i have bit poor knowledge
I have this bit of code which iScoll 4 displays correctly: <ul id=thelist> <li
OK, I have a bit of a conundrum. I'll say straight out that I'm
I have a bit of code which I think is correct. However, it should
I have a bit of a conundrum I need to deal with, and I'm
I have a bit of simple created with XAJAX, which replaces the innner HTML
I have a bit of a weird problem. I have a form with a
I have used bit field with a structure like this, struct { unsigned int
I have another Javascript regex conundrum... (apologies if this is a bit long-winded -
Have a bit of a weird one and hopefully someone can help out. 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.