javascript - How to validate a url address ( not syntax but the network )? -
i want validate url address returns valid page.
there 2 approaches 1 take.
- iframe - create , iframe points url
- ajax - create ajax request url , @ status codes - here fiddling
the ajax method not working because returns status code of 0 cross domain requests whether page there or not.
the iframe method not working b.c. can not find mechanism capturing status or errors of frame.
most of google hits i'm getting syntax checking.
fiddle code ajax
var urltest = function (url) { var xhr = new window.xmlhttprequest(); xhr.open('get', url, true); xhr.onreadystatechange = function () { console.log('readystate | status : ' + this.readystate + ' | ' + this.status); if (this.readystate === 4) { if (this.status === 200) { // console.log('4 | 200'); // xhr.responsetext; } } }; xhr.send(null); } urltest('http://www.google.com'); // cross domain give status 0
you may circumvent cors restrictions imposed on browsers means of proxy suggested here (without jsonp):
Comments
Post a Comment