How to stop continuous script execution using JSON?

Hi, I have a function to fetch remote content from other different domain into to the site. I need to stop the continuous execution of the script (say the script has gone to infinite loop). My below script stop the continuous request after 8 seconds on the same domain but it does not work for the cross-domain.

I’ve used JSON as AJAX are not supported on cross-domain architecture.

var req = $.ajax({
	url: "http://other-domain/remotefile.php?id=john&"+Math.random(),
	dataType: 'jsonp',
	timeout: 8000,
	success: function(data){
		$(document).append(data.remoteContent);
	}
});

Any clue?

You mean the whole ajax (or json) call is run within a loop?

I’ve used JSON as AJAX are not supported on cross-domain architecture.

What do you mean by ‘I have used JSON’? I don’t think that your given code does work in the cross domain.

Above code works similar to the below code:

var req = $.getJSON("http://other-domain/remotefile.php?id=john&"+Math.random() +"&callback=?", function(data){
	$(document).append(data.remoteContent);
});

My above code works in cross domain as I have used ‘jsonp’ datatype. I have placed huge sleep() in my remote file remotefile.php to have continuous script execution. Thing I need to do is to stop the request in between.