0

I want to just hit the url in javascript which will run in background not on frontend.

I had tried this code

var url = "http://yourpage.com";

req = new ActiveXObject("Microsoft.XMLHTTP");

   req.open("GET", true);

   req.onreadystatechange = callback;

   req.send(null);

but it not work for me.

could any one please suggest me how to hit url in javascript.

2
  • The req.open line has unmatched double quotes. Commented Nov 2, 2015 at 7:10
  • Sorry by mistaken pressed 'l' instade of closeing the quote Commented Nov 3, 2015 at 15:07

2 Answers 2

2

you should use cross browser JavaScript AJAX code, or better to use jQuery ajax see below sample code

    var url = "http://yourpage.com";
    var xmlhttp;

    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = callback;

    xmlhttp.open("GET", url, true);
    xmlhttp.send();
Sign up to request clarification or add additional context in comments.

Comments

1

I suggest you use either jQuery or AngularJs for sending AJAX requests rather than creating new ActiveXObject objects.

Girish gave you answer using pure javascript. I will give you an example of jQuery usage. Please see code below:

$.get('http://yourpage.com', function(){ /*callback*/ })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.