cashman04
cashman04

Reputation: 1173

ajax function not fetching url

I have:

function makeAjaxRequest() {
var url = '/queryjob/dbname/ip';
$.ajax(url,
{
    success: alert(response)
});
}

When I do a normal browser request on this url I get a response of 43(just a test response right now)

When I click the button I have to run this function, nothing happens. I don't see a get request in the log at all. Do I have some stupid syntax error or something? I am pretty new to js and ajax. I have another function that works where I get a url and act on the html response code, but this one is killing me so far.

Upvotes: 1

Views: 79

Answers (2)

ntzm
ntzm

Reputation: 4821

$.ajax({
   type: "GET",
   url: "/queryjob/dbname/ip",
   success: function (data) {
      alert(data);
   }
});

Yes, it was a syntax error ;)

Upvotes: 0

pmandell
pmandell

Reputation: 4328

You are not calling $.ajax correctly. Assuming you wanted to make a GET request, this is the correct syntax:

$.ajax({
    type: 'GET',
    url: url,
    success: function(response) {
        alert(response);
    }
});

You could also use $.get to accomplish the same thing:

$.get(url, function(response){
    alert(response);
});

Upvotes: 7

Related Questions