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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:50:59+00:00 2026-06-10T05:50:59+00:00

i have loaded a file into an array using ajax and after splitting it

  • 0

i have loaded a file into an array using ajax and after splitting it i need to save it to the file again.This all happens onClick of a button.

function updatetags(){

 var alreadyexistingtags;
 var responsetext;

 var r2 = new XMLHttpRequest();
 r2.open('GET', 'tagsupdated.txt', true);
 r2.send(null);

 r2.onreadystatechange = function() {
    if (r2.readyState == 4 && r2.status==200) {

        responsetext=r2.responseText;

        alreadyexistingtags=responsetext.split(' ');
        }       
  }
 }

i understand that javascripts are not server side and that’s why i cannot do what i want,but i’m sure there must be a way to write alreadyexistingtags[ ] to tagsupdated.txt.Any help?Perhaps i should somehow pass the array to PHP?And if so how is that possible given that PHP gets executed when the page loads,when i need to wait for the button to be pressed?

  • 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-10T05:51:00+00:00Added an answer on June 10, 2026 at 5:51 am

    You’re going to have to use AJAX or some other method to send the data back to your server, which can then write the file out.

    To do this, just create a new script on your server, say writearray.php, which accepts the Javascript array as input. Then use AJAX to send a request to that file with your array.

    The PHP file would look something like so (this is a highly simplified example):

    <?php
    file_put_contents("where_you_want_the_file.txt", $_POST['array']);
    ?>
    

    It looks like you’re just storing your Javascript array as a space separated list, so the Javascript would look something like this:

    var str = your_array.join('%20');   // URL encoded spaces separating array entries
    var params = "array=" + str;
    var http = new XMLHttpRequest();
    http.open("POST", "your_script.php", true);
    
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    
    http.onreadystatechange = function() {
        if(http.readyState == 4 && http.status == 200) {
            // Do something on success?
        }
    }
    http.send(params);
    

    The way this works, is you’re sending a POST with a field named array, which holds the textual representation of your Javascript array. The PHP code checks $_POST[‘array’] to get this value, then writes it to your file.

    Note that if you want to do anything more complicated, you should look into using JSON. And also as always be very careful with what you do with user data.

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

Sidebar

Related Questions

I have CSV data loaded into a multidimensional array. In this way each row
I have loaded an XML file using simplexml_load_file($filePath,'SimpleXMLElement', LIBXML_NOCDATA); And for most of the
I have navigation.html (static coded navigtaion ) file loaded on multiple pages, using jQuery
I have to do some processing on a file loaded by the user. This
I have a js file that is loaded for all pages which contains a
All, I am trying to load up a bmp file into a GLubyte array
I have an EXE loaded into a byte array, and I am trying to
So far I've loaded an entire file into an array (1 line per array
I have loaded an xmi file with an uml diagram. As a result I
I have a file with several column loaded in R. What I want to

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.