I have a local page that pulls data from a database and sends out a message. So I'm trying to have this page executed using javascript on "success" of another function. The problem is everything I've tried doesn't seem to execute that page, while the only success I've had on executing that page is using a window pop up, which is not desired.
This is the pop up code (undesired):
function sendMsg(){
var wnd = window.open("http://localhost/url");
if(wnd){
setTimeout(function () { wnd.close();}, 4000);
}
}
sendMsg();
And these are the codes I've tried but didn't execute the url:
$.get("http://localhost/url")
And this one which is from another answer here on SO.
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var response = xmlhttp.responseText; returned value
}
}
xmlhttp.open("GET","http://localhost/url",true);
xmlhttp.send();
How can I have this URL executed without opening it on the browser in any way? Just to be clear, I know the other two codes didn't work because I would have received a message.
if you really need a return data/page from get
you should do something like this.
$.get( "url", function( data ) {
console.log(data); // return data/page
alert( "Done load." );
});
@ use ajax
$.ajax({
url: "url",
type: "GET",
success : function( data ){
console.log(data); // return data/page
alert("Done LOad");
}
});
anything else can refer : https://api.jquery.com/jquery.get/
I believe jQuery's load() method may be useful for this. For example, have a div in your HTML and just set it to hidden in the CSS.
jQuery load() Method
HTML:
<div id='myHiddenPage'></div>
CSS:
#myHiddenPage {
display: none;
}
jQUERY:
$(funtion() {
$('#myHiddenPage').load('www.myurl.com');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With