How to Pass Parameters in Get Requests with Jquery

How to pass parameters in GET requests with jQuery

Use data option of ajax. You can send data object to server by data option in ajax and the type which defines how you are sending it (either POST or GET). The default type is GET method

Try this

$.ajax({
url: "ajax.aspx",
type: "get", //send it through get method
data: {
ajaxid: 4,
UserID: UserID,
EmailAddress: EmailAddress
},
success: function(response) {
//Do Something
},
error: function(xhr) {
//Do Something to handle error
}
});

And you can get the data by (if you are using PHP)

 $_GET['ajaxid'] //gives 4
$_GET['UserID'] //gives you the sent userid

In aspx, I believe it is (might be wrong)

 Request.QueryString["ajaxid"].ToString(); 

How to Pass Data in ajax call using GET Method in javascript

try this

$.ajax({
url: Globals.baseURL + "rest/grid/"+cuboid_id,
type: "GET",
dataType: "application/json",
data: {some_query_var : JSON.stringify(data)},
contentType: "application/json",
success: function(result){
console.log("***********************++++++++++++++*************************");
console.log(JSON.stringify(result));
//assert.equal(result !=null,true,"Response should not be null");
//assert.equal(result[0].error,"Whitebaord ID NOT FOUND","InValid Whiteboard ID");
assert.equal(1,1);
done();
}
});

"dataType json" in ajax jquery doesn't mean for formating JSON string in "data" attribute ..
you still need the query variable passing in the "data" attribute. wich is in this is case i use some_query_var.

How to pass parameters in $ajax POST?

I would recommend you to make use of the $.post or $.get syntax of jQuery for simple cases:

$.post('superman', { field1: "hello", field2 : "hello2"}, 
function(returnedData){
console.log(returnedData);
});

If you need to catch the fail cases, just do this:

$.post('superman', { field1: "hello", field2 : "hello2"}, 
function(returnedData){
console.log(returnedData);
}).fail(function(){
console.log("error");
});

Additionally, if you always send a JSON string, you can use $.getJSON or $.post with one more parameter at the very end.

$.post('superman', { field1: "hello", field2 : "hello2"}, 
function(returnedData){
console.log(returnedData);
}, 'json');

Pass parameters via ajax call in GET method using jquery

By default, web-api binds complex objects from the body. Since you making a GET, and there is no body, you need to add the [FromUri] attribute so that the properties of your model are bound from the query string values.

[HttpGet]
[Route("matter")]
public List<MatterLookup> LookupValuesForMatter([FromUri]ClientDetails data)

Alternatively, add a parameter for each name/value pair you are passing in the request

[HttpGet]
[Route("matter")]
public List<MatterLookup> LookupValuesForMatter(string clientId, .... ) // add simple type parameters as required

jQuery: 1 ajax request and one function: pass parameters to function

function buttonClick(e){
var param1ToBePassed = 1;
var param2ToBePassed = 2;
$.when(func1())
.done(function(){
$.when(
$.ajax(),
//here I want to call func2 passing in param1tobepassed and param2tobepassed
funct2(param1ToBePassed, param2ToBePassed ) //this line isn't working
)
.done(function(){console.log('ajax and func2 calls finished');})
});/// I have corrected this added closeing )

}

var func1 = function(){var deferred = new $.Deferred(); /*do somethig;*/
return deferred;
}
var func2 = function(param1, param2){var deferred = new $.Deferred(); /*do somethig with param1 and param2;*/
return deferred;
}

How to Get $.ajax() request parameter at success callback function?

    // want get data parameter
// {'sample':'test'}

Pass data as a property to jqxhr object at beforeSend, get object at success.

$.ajax({
url: 'example.com/something',
method: 'GET',
data: {
"sample": "test"
},
beforeSend: function(jqxhr, settings) {
jqxhr._data = settings.url.split("?").pop();
},
success: function(data, textStatus, jqXHR) {
// want get data parameter
// {'sample':'test'}
var _data = jqXHR._data.split("&").slice(0, 1).pop().split("=");
var obj = {}; obj[_data[0]] = _data[1];
console.log(_data, obj);
// var obj = {};
// someone answered that could get below code but I couldn't get it
// console.log(this.data); => X
}
})

jQuery .ajax() - add query parameters to POST request?

jQuery.param() allows you to serialize the properties of an object as a query string, which you could append to the URL yourself:

$.ajax({
url: 'http://www.example.com?' + $.param({ paramInQuery: 1 }),
method: 'POST',
data: {
paramInBody: 2
}
});


Related Topics



Leave a reply



Submit