So right now I'm trying to understand this piece of code:
VADER.ATTRACTION = {};
VADER.servicebaseurl = './services/'
var scriptLocation = VADER.servicebaseurl + 'attraction?callback=?';
$.ajax(scriptLocation, {
dataType: 'jsonp',
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
},
success: function (data) {
VADER.ATTRACTION.data = data;
}
});
I can understand the gist of most of it, it basically uses jQuery
's .ajax()
method to get data. My question is on the line right here:
VADER.servicebaseurl = './services/'
var scriptLocation = VADER.servicebaseurl + 'attraction?callback=?';
What does ./services/
and attraction?callback=?
come from?? Especially the attraction?callback=?
part, is that ajax
? I'm pretty sure that attraction
is the table name in the database..... I just can't figured out what that is the syntax, and I've googled callback=?
to no avail so....
Maybe this is a dumb question, but I'm really confused since I'm new to ajax
,jQuery
, and javascript
in general..... any help would be greatly appreciated, thank you!!
attraction?callback=?
are just extra bits of the URL that are processed by the server. You'd need to go and examine the server side code to find out what it does.
All ajax does is send a request to a URL and gathers whatever is returned to it. The URL itself doesn't need any special bits that are ajax specific, so in the above example, you could put anything into scriptLocation
and if it was a valid, error-free URL that returned something, you'd get that in your success function.
In your case data
is returned, then assigned to the javascript object VADER.ATTRACTION
- the URL queried by ajax only has to create a successful request for this code to be executed and any code could be executed on success.