0

I need to perform the following GET request,

telnet somesite.com 80 GET /index.html HTTP/1.0 

using javascript, jQuery.

I've tried to follow the instructions in this site in particular the following code:

$.ajax({ url: 'http://somesite.com', success:function(data){ alert(data); } }); 

but It doesn't work!

Where am I wrong?

3
  • Which http error do you get? Commented Oct 31, 2013 at 10:55
  • 2
    You cannot do cross-domain ajax query. see Same origin policy Commented Oct 31, 2013 at 10:57
  • There's nothing wrong with the code itself, so it does suggest that you're trying to access a page on a different domain, as suggested by @psal above. en.wikipedia.org/wiki/Same-origin_policy Commented Oct 31, 2013 at 10:58

3 Answers 3

1

Try this one:

$.ajax({ type: "GET", url: "http://somesite.com", timeout: 300000, contentType: "application/json; charset=utf-8", success: success, error: failure }); function failure(response) { alert(response); } function success(response) { alert(response); } 
Sign up to request clarification or add additional context in comments.

2 Comments

It returns [object Object]
Seems like there is some issue with URL , is there any method you want to access from this URL?
1

by your code im assuming you are doing a cross domain ajax request. Which are automatically blocked by the browser.

you can either use the allow domain header using Cors see this Cross Domain Get Request in JS/JQuery

or switch to JSONP

Comments

1

If you want to perform a cross domain request try this

Working DEMO

You can use this in your head tag

<script src="https://rawgithub.com/IonicaBizau/jQuery-cross-domain-requests/master/js/jquery.xdomainajax.js"> </script> 

code

$.ajax({ url: 'http://somsite.com', // Or your web page link type: 'GET', success: function(res) { alert(res); } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.