Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Get Request on HTTP URL

i've recently tried to get some Response from an URL using jQuery. Therefore I copied a get request sample of jQuery API Get Request Tutorial into my project and tried to run it, but my debugging messages showed me, that it can't go further. I tried the javascript Ajax Library using a simple request, but it didn't work.

So i'm asking you, if you could help me somehow.

And this is all what i do, but there is no response.

var url = "http://www.google.com";

$.get(url, function(data){


    alert("Data Loaded: " + data);
    });

Did i probably forgot to include a ajax or jQuery library. For a better understanding, i have c and obj-c experince, this is why i think, that a library is missing.

In each sample there is just a short url like "test.php". Is my complete HTTP url wrong?

Thanks for your answers in advanced.

Br Nic

like image 582
NicTesla Avatar asked May 09 '11 20:05

NicTesla


1 Answers

I have provided an example scenario to help get you started:

<!-- Include this jQuery library in your HTML somewhere: -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script

This is probably best to include inside of an external JS file:

//Listen when a button, with a class of "myButton", is clicked
//You can use any jQuery/JavaScript event that you'd like to trigger the call
$('.myButton').click(function() {
//Send the AJAX call to the server
  $.ajax({
  //The URL to process the request
    'url' : 'page.php',
  //The type of request, also known as the "method" in HTML forms
  //Can be 'GET' or 'POST'
    'type' : 'GET',
  //Any post-data/get-data parameters
  //This is optional
    'data' : {
      'paramater1' : 'value',
      'parameter2' : 'another value'
    },
  //The response from the server
    'success' : function(data) {
    //You can use any jQuery/JavaScript here!!!
      if (data == "success") {
        alert('request sent!');
      }
    }
  });
});
like image 63
Oliver Spryn Avatar answered Oct 09 '22 02:10

Oliver Spryn