So I can't seem to find an straight answer to my problem.
What I want to do is load a JSON file that's located on a specified URL. It's a large complicated JSON file. Basically, I've been trying to use AJAX to 'get' the file all night long. I've used the $.getJSON Jquery shortcut too, without any luck. I believe the server isn't allowing for AJAX requests, but if I enter in the URL I can access the file without a problem.
My question is, is there any way I can get the file so I could use it in order to create this little mock up site that I need to create?
Is this possible?
I've tried looking for a way to just rip the text off of the URL and then just turning that into a JSON file so I could parse it, but I haven't found any relevant information on this tactic.
If you have any ideas, please let me know, thank you! :D
Related
I'm implementing a small image uploading function in my web page, nothing too fancy, and to that end, I think vgy.me is a good tool. From what I understand, we can upload an image to the site via a POST method in a form. It returns a JSON response for every image uploaded, which contains a link to the image among other things (important because I intend to use that link for future purposes). There's even a helpful little example of the same on its API page (link).
My question is, how can I get that JSON response for my use using vanilla JavaScript? My initial searches have turned out techniques which pertain to server-side, which obviously I can't implement because it isn't my server I'm using. Is there a way to use the default POST method of HTML to get the JSON value, or perhaps I've misinterpreted the instructions?
I'm not using the jQuery code given on the page, because I've no knowledge of any JavaScript framework, and I'd rather not simply copy and paste if I could help it.
I have a URL(that i am not in control of) that returns a JSON string. This JSON string contains a URL that i am trying to load with JavaScript/jQuery AJAX. What I’m running in to when loading the JSON string is a Cross-Domain issue.
I know a couple of workarounds for fixing Cross-Domain issues like:
Using JSONP by adding "callback=?” as a parameter.
Call for example a PHP script and letting it load and return the JSON.
My issue is that i JSONP is not supported and i can’t do the convinient method of using PHP on the server because of the problem below:
The URL in the JSON data has one dynamically generated parameter. As from what i understand when playing around with it the dynamically generated parameter is that it is defined by whats loading the JSON, specifically the User-Agent string. But it is also depending on the IP loading the JSON. This is important because the URL inside the JSON string will return 403 forbidden if whats loading the JSON is not matching whats loading the URL.
I hope i have explained my issue well and i appreciate all help i can get.
As Quentin said, it sounds like a security measure designed to stop you doing what you are trying to do. So you can't do it. That, or you implement a query from a server and reverse-engineer how to deal with the dynamically-generated parameter, but note that you'll almost certainly be violating some terms of service that the service in question seems to take seriously. And so after a few days of working, don't be surprised if it stops working when they figure out what you're doing and patch it.
I am developing my first website. At this time i am generating a new html design that would be a ticket.
From my main page, i will load this html when the user clicks the "See ticket" button. This html has a table which is filled on document.ready with javascript. The data used is a JSON created in the main page.
I coded a working solution using localStorage. The problem is that the next step is to convert that HTML website to PDF and the software i am using does not work properly with localStorage, so i need to pass the JSON from main page to the ticket page. I can't neither use URL encoding cause string could be sometimes longer than 2000 characters and it is not productive.
So i thought that maybe i could do and $.get call from the ticket.html to index.html and get the needed JSON. Is this approach correct, or is there any better solution?
Regards
As suggested earlier comments, you need to use serverside code to accept post params and you need to do a ajax post to send the data. This is very good approach. I have one more idea for implementing this.
Let say you open ticket.html in a window.open. And have a JS function ( say GetValue) in index.html, that returns JSON . So you need to get JSON in ticket.html.
You need to define a JS function in ticket.html , using windown.opener.GetValue() , you can get JSON value.
Hope, i am in same direction, which you need. If not, please clarify.
Other way, would be use iFrame and use message communication to pass large data between them, you are interested in this, please read this - https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage
I'm thinking of doing some online file manipulation for mobile users, the idea being that the user provides a URL to the file, then the file contents are modified by the JS, and can then be downloaded. But I haven't been able to figure out how to get the file when it's on a separate domain using just JS.
Is this possible? If so any hints or examples would be appreciated.
Just wanted to add that part of what I wanted to do was make it available without my hosting it. I'm thinking of something like a a file they can host somewhere,and then all of the bandwidth is their own...and that of wherever they are getting the file from of course.
The only way to load contents of a file on another domain is from within a <script> tag. This is how JSONP works. Look into getting your target file into this format.
The other way would be to use a local proxy. Create a web service method that loads and returns the contents of the file, then call that locally using your favorite JavaScript framework.
Depending on how you think of public webservices, and within some limitations I'm still mapping, you can do this using an ajax call to YQL, like so.
(will expand the answer later).
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20data.uri%20where%20url=%22http://t3.gstatic.com/images?q=tbn:ANd9GcSyART8OudfFJQ5oBplmhZ6HIIlougzPgwQ9qcgknK8_tivdW0EOg%22
One of the limitations of this method is file size, it currently tops out at 25k.
I asked the almost the same question before also, but i have not yet been able to figure out how to solve this issue of mine.
I have been assigned a project, in which I get a .xml file, which has field like, <TITLE>, <AUTHOR>,<ABSTRACT>, <COMMENT> and the <COMMENT> tag comes empty in the .xml, rest all the fields are already filled.
I have to parse this xml, and generate a report of it, i have already done this.
But the problem is, that i have a dropdown box for every COMMENT field in my report, and when i make change in the drop down box it shows the change on the client page but it does not update the xml file on the sever.
How can i do that. Is there anyway to insert, delete, update xml nodes?
Kindly help me with this.
I am using DOM to parse the xml file.
Also i read somewhere to XMLDocument class to make changes in the xml file. But if that is possible, can you please tell me about where can i find samples of xmlDocument used to make changes in xml file.
I appreciate you help.
Best
Zeeshan
The first place to start would be at w3schools. Once you can make changes to your document e.g.:-
var textNode = dom.createTextNode(myText);
dom.documentElement.selectSingleChild("COMMENT").appendChild(textNode);
You then need the servers assistance to accept the new XML document. You will need either a server script that accepts the XML document sent using a POST request or for the server to support PUT request to replace the original XML url. You will need the XmlHttpRequest object to acheive that.
XmlHttp on W3Schools can give you a beginners guide to doing that.