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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:21:01+00:00 2026-05-24T10:21:01+00:00

I have a jquery script that collects data from different sites and saves it

  • 0

I have a jquery script that collects data from different sites and saves it through ajax and php to a sql database. At the moment the script saves each collection from a site separately. I want to change that, so that the script collects all the data in an array and when it is finished collecting it passes the array on to the php file which will save it in the database.

My problem now is, that I can’t send the array after the “each loop” to the ajax statement. If I send the array inside the “each loop” it works (at the moment I save the data in a session on the php file, so that I can see it’s structure and can adapt the pdo statement accordingly), but then I have a post request after each “loop”. I want to avoid that, so that I have just one POST request with the whole array at the end. But if I use the ajax post request after the “each loop”, the array I get is just empty. I thought I made the array global, so that I can use it outside the each statement, but for some reason it doesn’t work.

Do you have any idea how to solve the problem? Here is the script:

$('#ScanButton, .ScanButton').click(function() {

var array = ["http://www.xyz.com/bla/bla/summary.html",
             "http://www.xyz.com/blu/blu/summary.html",
            ];

dataArray = [];

$.each(array, function(n, val) { 


$.get(val, function(res) { //get the html source of this website

  var data = {

  }

  dataArray.push(data);

// If I use the $.ajax statement here, it works and a correct array is submitted. But then I have a a POST request with each loop..
});

});

//If I use the $.ajax here, the array I get is just empty. Any Idea how to solve this?
data = YAHOO.lang.JSON.stringify(dataArray);      



  $.ajax({
    type:           'post',
    cache:          false,
    url:            'test.php',
    data:           {myJson:  data}
    });

  return false;

  });

Do you have any idea where the problem might be? If you need more information, please let me know.
Thank you very much! 🙂

  • 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-24T10:21:02+00:00Added an answer on May 24, 2026 at 10:21 am

    [Edit] lol I’m an idiot, anyway, the reason your array is null is because the get requests are asynchronous, and are probably not completing before you send your final array.
    Either make your gets, synchronous, (probably not something you want to do) or wait to send the final array until all your gets have completed.

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

Sidebar

Related Questions

I have a PHP and jQuery script that creates search result suggestions from a
I have a jQuery tab script that gets content from a PHP file defined
I have a jQuery tab script that gets content from a PHP file defined
I have some jQuery code. I have called an Ajax function file, file.php, that
I have a jQuery script that I am including on a PHP page that
I have a jquery script that searches a php file that produces an XML
I have a jQuery search script that queries a PHP file then parses the
I have a jquery script that attaches a click event to every link, running
I have a jQuery script that changes the src attribute of an <img> and
I have a jQuery script that will display specific divs depending on which select

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.