I want to get the <title>
of a page using its URL.
For example,
if the URL is (https://www.google.co.kr/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=ajax%20fail),
what I want to get is (ajax fail - google search)
Here is my code and unfortunately it does not work. This code return error code: 0, undefined, no transport.
$(document).ready(function () {
titleInfo = {
url: "http://google.co.kr",
title: "abcd"
}
$('#target').text("SS");
requestAjax('http://gorapaduk.dothome.co.kr', titleInfo);
});
var requestAjax = function (url, data) {
$.ajax({
url: url,
cache: false,
success: function (html) {
alert(html);
request(html, data);
},
error:function(request,status,error){
alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
}
});
}
var request = function (html, data) {
var matches = data.match(/<title>(.*?)<\/title>/);
var spUrlTitle = matches[1];
data.title = spUrlTitle;
$('#target').text("spUrlTitle");
console.log(data.title);
}