0

I am trying to download from the server (using my local WAMP) a csv file with using the code below and it does not work. I suspect hat I need to use AJAX however I am not familiar with Ajax yet.

The content of the csv file is:

1,2,3 4,5,6 7,8,9

Your help is appreciated. Here is my code:

<script type="text/javascript" src="jquery-2.2.0.min.js"></script>
<script type="text/javascript">

function UpdateFunction() {
$.get('example.csv', function(data){
example_array = data.split();
})
}

UpdateFunction();
alert (example_array);

Menachem
  • 265
  • 1
  • 4
  • 17
  • Please keep in ming that $.get() IS an AJAX call. It is executed asynchronously so make sure it has completed before requesting its data. – ViNi89 Jun 11 '16 at 23:42
  • Thank you for your quick reply. I actually want to make a synchronous AJAX call. Can you modify my code to make it a Synchronous call. – Menachem Jun 11 '16 at 23:50
  • *"I actually want to make a synchronous AJAX call"*....no you don't! That is a terrible practice and is now deprecated by browser vendors. Use common asynchronous approaches that are well documented. the link above is extremely well written and thorough – charlietfl Jun 11 '16 at 23:51
  • OK. Thank you for your advice. Because my code will have to wait until it gets the data, I thought that a Synchronous call will be simpler. However I will take your advise and learn how to handle an asynchronous call. – Menachem Jun 11 '16 at 23:55
  • Right...sounds simpler but it also blocks everything else in page while it is occurring and if it fails or takes a long time so does page break. – charlietfl Jun 11 '16 at 23:58
  • Thank you again for your advise. It was easy to implement and it works great and consistent. – Menachem Jun 12 '16 at 02:18

0 Answers0