Home > Uncategorized > Find Backlinks to a website using AJAX

Find Backlinks to a website using AJAX

 One of the most basic SEO tools is a backlink checker, and if you need to fine tune this, then automating the check will save you lots of time, so this is my experience with the SEOMOZ links API  using AJAX.

The basis of the API, is a call to the URL: http://lsapi.seomoz.com/linkscape/links/<URL>?Scope=page_to_page&Sort=page_authority where <URL>  is the site in question. This throws up the basic HTTP authentication challenge, so I’ve included the username and password:
Your Access ID: member-2dd03f462e
Your Secret Key: 018a47ae0940f6342577b24dfce80a5f

This code requires the Base64.js code library from www.webtoolkit.info, to base64 encode the HTTP authentication. Note that this code will only work when run locally from Internet Explorer, it won’t work hosted online due to cross-domain restrictions.

  <input type="text" name="input" id="input" value="www.xyz.com">
  <input type="button" onclick="BacklinkCheck()" value="Check">
  <div id="output"></div>
  <script language="javascript">
   function BacklinkCheck()
	    var auth = authenticate('member-2dd03f462e','018a47ae0940f6342577b24dfce80a5f');
		var input = document.getElementById("input");
		var output  = document.getElementById("output");
		output.innerHTML = "working...";
		var http=new XMLHttpRequest();
		var url = "http://lsapi.seomoz.com/linkscape/links/"
		url += input.value + "?Scope=page_to_page&Sort=page_authority";
		http.open("GET", url, true);
		http.setRequestHeader('Authorization', auth);
		http.setRequestHeader('Content-type', 'text/html; charset=unicode');
		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) {
				 var html = "<table>"
				 var jsondata=eval("("+http.responseText+")");
				 jsondata = jsondata.sort(
					function(a, b){
					 if (a.upl < b.upl) //sort string ascending
					  return -1
					 if (a.upl > b.upl)
					  return 1
					 return 0 //default return value (no sorting)
				  for (i in jsondata )
					var backlink = jsondata[i];
					if (i % 2 == 0)
						html += "<tr>"
						html += "<tr>"
html += "<td width=50%><a onclick=\"this.innerHTML='" + backlink.uu.replace('\'','') + "'\">"+ backlink.upl + "</a></td>";
html += "<td width=50%>" + backlink.ut + "</td>";
html += "</tr>";
html += "</table>";
output.innerHTML = html;
if(http.readyState == 4 && http.status != 200)
alert("Something went wrong");

function authenticate(user, password) {
var tok = user + ':' + password;
var hash = Base64.encode(tok);
return "Basic " + hash;
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: