John Mathews John Mathews - 2 months ago 24
Javascript Question

JavaScript which Opens URL and echo its content in a Div

JavaScript which Opens URL and echo its content in a Div.

I want this Script to Open A lot of URLs one by one.

I Tried Below Code. Not working, I'm seeing Network Tab. No Request is initiating.

JSFiddle: https://jsfiddle.net/at4gdnng/3/

<input id="start" value="1">
<input id="end" value="100">
<a href="#" id="submit">start</a>

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<div id="target"></div>


<script>

$("#submit").click(function(){

var start = document.getElementById("start").value;

var end = document.getElementById("end").value;

for (i = start; i < end; i++) {


var url = $(this).attr('href');

url = 'http://example.com/checker.php?id=' + i;

$('#target').load(url); sleep(1000);


}

});

</script>

Answer

This doesn't work on JSFiddle because it uses https and the content you're trying to load is on an http domain. If you open the javascript console (Ctrl + Shift + J in Chrome), you can see errors about Mixed Content.

VM69 jquery-3.1.1.js:9536 Mixed Content: The page at 'https://jsfiddle.net/at4gdnng/2/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://example.com/checker.php?id=1'. This request has been blocked; the content must be served over HTTPS.

enter image description here