I want to make a javascript application able to parse an html of an external URL.
The URL will be in a different domain than my server. My idea is to get the html
of the external URL I want to parse as a String, and then parsing it (I have to check
only the content of one tag in the head of html)
1)How can I get as a String the html of an external URL in Javascript?
2)How can I parse such retrieved String?
I have red about jquery and ajax; It seems that Ajax will not allow me to do it because doesn't allow cross-domain operations. So maybe jquery can retrieve the html and parse it.. other similar post in this forum were too complicated and didn't come rightly to my point.
thanks everybody for the help
Related
Hey im very new to web developing and i have a big problem.
Im trying to write a javascipt script which does a jquery getJSON request to a php file which then reads out the content of a JSON file and echos them back to the javascript. Now im getting a access-control-origin-header. I don't want to change the header. Is it somehow possible to read the contents of a json file with javascipt? I am the one writing the json file so is it not possible to give everyone access to that one file?
Instead of sending a request to the other origin from client-side, have the getJSON() function call a URL on the same origin. From this endpoint some server-side code can call your PHP script on the other origin and return the result back in it's response.
As the title states. I am looking to get the extension of the file, even if it is hidden via htaccess, for example:
.../whatever/index
Imagine it was a php file, is it possible to know that and extract it via JavaScript or jQuery?
Thanks in advance, can't find it anywhere. All I can find is people trying to actually hide the extension.
To achieve this you need some sever-side coding where you can request which file is behind the given path, so when you pass "/whatever/index" you server should returns 'whatever.php' and from that information you could extract the file extension.
Javascript itself doesn't know anything about what/how things are organized on the backend
I want to load a external webpage on my own server and add my own header. Also i need to use the data from the external website like url and content (i need to search and find specific data, check if i got that data in my system and show my data in the header). The external webpage needs to be working (like the buttons for opening other pages, no new windows).
I know i can play with .NET to create software but i want to create a website that will do the trick. Can this be done? Php + iframe is to simple i think, that won't give me the data from external website and my server won't see changes in the external url (what i need).
If it's supposed to be client-side, then you can acquire the data necessary by using an Ajax request, parsing it in JavaScript and then just inserting it into an element. However you have to take into account that if the host doesn't support cross-origin resource sharing, then you won't be able to do it like this.
Ajax page source request: get full html source code of page through ajax request through javascript
Parsing elements from the source: http://ajaxian.com/archives/html-parser-in-javascript (not sure if useful)
Changing the element body:
// data --> the content you want to display in your element
document.getElementById('yourElement').innerHtml = data;
Other approach (server-side though) is to "act" like a browser by faking your user-agent to some browser's and then using cUrl for example to get the source. But you don't want to fake it, because that's not nice and you would feel bad..
Hope it gets you started!
I have some data that I'm retrieving using JSONP from a remote server. The content contains HTML and I need to make it so the characters render properly instead of printing the tags out. For example, if something has bold tags, it should just appear bold and not have the strong tags around it.
This needs to be done in JavaScript/jQuery. Just about everything I've found in search results uses some type of server side code.
If you read http://en.wikipedia.org/wiki/JSONP you can understand that you need to wrap you content into a Javascript function such as:
remoteScripts.js:
function getContent(){
return 'YOUR HTML CONTENT';
}
and so in your HTML page you can do via JQuery:
$('YOUR ELEMENT').html(getContent());
I work on a website which is all done in iso-8859-1 encoding using old ASP 3.0. I use Yahoo YQL to request data (XML) from external websites but which I request to be returned as JSON-P (JSON with a callback function so I can retrieve the data).
The problem I am facing is that YQL seems to always return data encoded in utf-8, which is bad for me when I try to display any textual data retrieved from that query. Characters like é, à, ô, get gibberished in IE6 & IE7 since the encoding does not match.
Anyone knows how to convert utf-8 data retrieved via JSON-P with YQL to iso-8859-1 and be displayed correctly ?
I already tried that solution, but it does not work. Server side functions are not an option too, ASP 3.0 does not include function such as utf8_decode.
Thank you
I have no idea whether this will work, but here's something you can try if you want.
A <script> tag can have a charset attribute specified when referencing a remote JS file. See the theory here. This definitely works for content that is stored inside the JavaScript file and e.g. output using document.write.
Whether the implicit conversion works for data fetched by a routine defined in that file through JSONP? I have no idea. My guess is, probably not. I can't test it right now but if you do, I'd be very interested in the outcome.