0

Is it possible to use jQuery ajax to look up specific values from a csv file as needed, on say a button click?

For example, say the CSV has the following structure:

country, capital, population, currency,
france, paris, 65950000, euro,
italy, rome, 59685227, euro,

Could I return only the population count for italy?

I have seen a couple examples where the entire csv file is converted into js arrays before any value is returned, though would prefer avoiding this method if possible as the csv file is likely to be very big.

1 Answer 1

1

You don't need to convert entire csv into js arrays:

  1. Make a country dropdown in your HTML
  2. On button click, pass POST parameters such as country, population to your server-side script (php, asp.net, whatever)

    data: { country: "italy", find: "population" }
    
  3. Read csv file on server

  4. Find row that contains italy as country and extract your desired values, for example population
  5. Only return your desired values back to client and read them in $.ajax() response

See Examples at the bottom of jQuery ajax page

Sign up to request clarification or add additional context in comments.

1 Comment

is their no client side alternative? was hoping the csv file could be accessed in the same way as you would json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.