I have an AJAX request in function in another file. I need to pass json parameters to this request. Here are sample params which work in my ajax:
{firstName : name, lastName: sname, email : email, password : pass},
I would like to pass data as a function’s parameter. I tried to pass it as a string param, but my function recognise it, and sends as a string. Which does not work.
My function with ajax request:
function ajax(url,contentType,data)
{
$.ajaxSetup ({
cache: false
});
console.log("Starting AJAX");
$.ajax({
crossDomain: true,
type: 'GET',
url: url,
callback: 'jsonpCallback',
jsonpCallback: 'jsonpCallback',
jsonp: '_jsonp',
data: data,
scriptCharset: "utf-8",
contentType: contentType,
dataType: 'jsonp json',
timeout : 5000,
success: success,
error: error,
});
console.log('AJAX done');
}
I tried this:
ajaxRegister('http://lalal/register','application/json',data);
ajaxRegister('http://lalal/register','application/json','{firstName : name, lastName: sname, email : email, password : pass}');
The point is that when I put this sample json as a data parameter of the request, it works. I want to be flexible and be able to put any json in parameter and send it as a request’s param.
The answer is passing parameters in ” “. It helped, but was not necesserly when locally adding data.