$.post() html to another html file - javascript

Is it at all possible to post HTML to an HTML file using jquery's post method.
for example:
$.post("database.html", "<div>Content</div>")
once a button is clicked I want to post to the database file and have this current file load in content from the database file using.
$.load("database.html")
Does anyone know how I could implement this method properly?

If I rewrite your question a bit: you want to pass data between two html pages. If you only use static html you cannot do that with javascript only. You have to send the data to a server and then use this data in your second html file.
But I think you quite misunderstood what http can or cannot do, I would recommend reading mozilla explanation

It is possible to pass HTML content in POST from one HTML page to another. But in order to use or process received the data at the second HTML page, you'll need a programming language.
Read the accepted answer to question How to read the post request parameters using javascript.

Related

PowerBi: Query HTML table

What I need
I need to retrieve data from this source . Let's assume I must use only PowerBi for this.
What I did so far
If I use the basic web source option, then the query is just basically an htlm parsing with which I can easily get the data found in the html scope of the page, example:
Source:
The steps I'm following through Web source option:
Query:
(to simplify the example, assume we don't need the dates)
You can download that example .pbix file here.
The problem
The problem is that I need more data, which can't be accessed through the html preview. For example, let's imagine I need to retrieve the data from January 2010 to April 2020. Those king of queries can only be done via this button located in the webpage (which exports the requested data to an Excel workbook):
The idea is to get this process automated, so going to the source and export the excel file all the time is not an option.
Inspecting the element I realized that what it does is execute a javascript function:
The question
As a PowerBi/PowerQuery noob I wonder: Is there any way I can get that data directly with PowerBi (maybe calling the js function somehow)? If there is so, then how?
Thank you in advance.
The solution to my case was to use URL parameters to retrieve de data without parsing the html table.
❌Original URL I was using:
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20400
✔️New URL for the query, adding some parameters:
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20400&Idioma=1&FecInicial=2010/01/01&FecFinal=2040/01/01&Filtro=0&Exportar=True
This procedure only works in this case, because obviously the parameters will not be the same on other web pages.
However, I post this answer to keep the main idea for those who are in a similar situation: first try with the appropriate url parameters to get the data in a different format. Of course you first must know which are the available parameters, which is a limitation.

How could I send data to an HTML file while loading that page with jQuery but without PHP?

I need to do this for a university assignment. I can only use jQuery and JavaScript. My professor has given us an API for interacting with the database, so that means we have a directory containing a lot of .php scripts we can call from the jQuery and JavaScript.
Basically I have an Accounts.html page which will display user information based on the clicked list item in another page called Projects.html which contains an ul with one li for each user.
I have everything ready to go up to this point, but I don't understand how I could possibly send data to a .html page then load it from a script within that page without making it a .php page (meaning I'd be able to use POST data).
I suppose I could possibly use GET data, but I'd much rather use POST.
Or can you use POST with .html pages?
Please share your thoughts as to which solution would be best.
Thank you!
Your question is still a bit vague...it would be better if I knew exactly what you were trying to do. In terms of a general idea of how JavaScript can load other files...
You can load external HTML files into sections of your code with jQuery's load method:
http://api.jquery.com/load/
Or you can more directly control the data using jquery's get method:
http://api.jquery.com/jquery.get/
and then subsequently processing the HTML data to get the data you need out of it. E.g. you could use get to get the HTML data...then put that HTML data into jQuery and grab the UL tags out of it and do further processing on those:
$.get('some/file',function(result) {
var $uls = $(result).find('ul');
}

Process cross domain xml

In a web project using jsp, I have following requirement
Upload a file (say an image) to a different domain, which returns an xml that includes details of uploaded file (eg: path of uploaded image etc).
How do I capture this xml to save details in db?
I cannot do a normal html form submit, since I lose control after that. So I tried to implement this by setting form target to an iframe. But I cannot process contents of iframe?
Any suggestions how I can accomplish this?
Can I process this using yql?
Yes, you can do this using YQL. Not easy though, and you'll need to set up your own YQL table.
Each YQL table is a XML file describing how to operate on data. The YQL XML specification allows you to define an <execute> element that you can use to write JavaScript code that does almost anything.
Inside this <execute> block, you can use the y.rest object to POST data somewhere else.
You'll probably have to encode the file using base64 to be able to actually POST data using the YQL syntax, something like INSERT INTO mywebsite.files (name, data) VALUES ('foo.png', 'KBB987987JJBHBGV==') (second param is a illustrative base64-encoded file).
Assuming the server you are submitting the file to is not under your control (so you can't use CORS), you have proxy the request through your own server.
You can't use YQL as you can't make post requests with it.

Reading in a text file in Javascript or Jquery

Im new to Jquery and Javascript and im wondering how can i read information from a text file stored on my server and write back to this file again afterwards? I couldn't find much information after googling the problem
I would also like to read in the data line by line and store it in an array, is this possible?
Thanks,
Matt
I think you want to use some server side programming. If you want the data on the client, you can use javascript or jquery using some ajax solution.
You can read the file if server allows to get it via http but you cannot write to it
Read file can be done by simply $().load(url)
You could use a RESTful API in order to achieve this. Use HTTP GET (jQuery/AJAX) to get the contents of a file, edit what you wish, and use a HTTP PUT (jQuery/AJAX) to write the changes back to the server.
Read information - yes via ajax call. The javascript will get the text from the page - whatever it is html/php/asp and return it to the calling page.
Read line by line - it is possible if you write it yourself. There is no built-in function for this. But then the text should be divided by lines.
Write back - JavaScript can`t do it by itself. You need an ajax and serverside.

Flow of Jsp -> Javascript webpage (Ajax?)

I am making a website but I get a bit lost programming dynamic sites.
The user needs to enter x (inside a textbox), click submit, process in java (serverside) and present outcome as a report to the user (using javascript).
I'm at the moment using JSP to process the users input but now I need to pass the JSON code into the javascript. The javascript requires JSON data.
At the moment I have JSP which returns the necessary JSON code and the Javascript which works with hardcoded JSON code. I need to somehow store the returned JSON (from the JSP) in a variable and pass it to the Javascript. I have a vague understanding of AJAX - i'm just unsure if this is possible and how to link it all together.
Thank you.
Your JSP "page" can simply generate JSON directly. There's no reason the output from JSP has to be HTML. From the client, therefore, you POST to the server, the JSP runs, and the result (pure JSON from your JSP) is sent back to the client as the ajax response.
Sounds like the perfect place for AJAX - you can submit the request with javascript, and when it comes back process it further with javascript. Unless you want the page to refresh.
If you are using jQuery, you can look here to see how to implement it, should be relatively painless: http://api.jquery.com/jQuery.post/

Categories

Resources