Help with AJAX request on non JSON page

Help with AJAX request on non JSON page
0.0 0

#1

Hello all,

I’m currently working on a personal project and I’ve run into a bit of a problem. I’m trying to import a bunch of values which are going to stay in the back end of the project, however the page in which I need to grab the values from, is extremely long and all in string form.

I thought about trying to use an ajax request through jQuery but I’m not sure on how I would go about doing that becasue the page is not strictly JSON data. Please let me know what you think.


#2

Jquery Ajax can receive back raw HTML response, it doesn’t have to be always Json. Once you get back the HTML response, just use regex or string manipulation to get the values you need.


#3

so if you retrieve the data using $ajax, do you get a responseText that resembles an HTML file?

if so, you can probably use jQuery to find the table elements and pull the data you need from that HTML string.

The problem might be the table you’re trying to parse is very barebone, without id or class, so you might have to hard code how exactly to parse the HTML


#4

@psychometry @owel

I’ve tried making some ajax requests, however it keeps giving me an error with “jsdom”. I’m not quite sure what to do or what the cause of this is. Let me know if you know how to correct this.


#5

If there is an error with json formatting, you may get an error message. So first verify the structure is valid . Cut and paste the json data and plug into one of data validators on the web. Google json data validation.


#6

From the link you provided, it seems like you are just trying to get the value of a bunch of constants, they don’t update and while it’s long, it’s not such a large quantity that you need to use an api, have you consider downloading the html and just locally extract the information by working with the DOM object? Do what is commonly known as web scrapping? If you google web scraping, you should be able to find some hints


#7

I love JSON formatter to validate and formatting JSON data.