when we call $.ajax with GET method
$.ajax({
type: "GET",
url: "test.js",
data: "id="+id
});
how to pass data to request file
is above given code is correct for that
Your one is correct (but data
, not dataType
), as well as
$.ajax({
type: "GET",
url: "test.js",
data: {
id: id
}
});
is correct too
$.ajax({
type: "GET",
url: "test.js",
data: "id="+id, //not dataType
success: function(response) {
//do osmething with response
}
});
The option to pass data as part of the request is called data
, not dataType
.
Have a read of the different options you can pass at: http://api.jquery.com/jQuery.ajax/
You can either craft the query/data string yourself, or let jQuery do it by just passing an object.
so your ajax signature should look something like this:
$.ajax({
type: "GET",
url: "test.js",
data: "id="+id
});
or
$.ajax({
type: "GET",
url: "test.js",
data: {
id: id
}
});
should both work