I have developed an app using cordova(version 6.3.1). I have checked it on nexus 5 and nexus 6P and everything looks fine, but i tested it on genymotion emulator and galaxy S6, but they didn't send any request(I checked server logs).
Does it anything to do with security problems? Or there is another problem?
The ajax POST method is the code below.
$("#login").click(function() {
$.ajax(serverUrl + "/login", {
data: {
email: userEmail,
password: userPassword
},
dataType: "json",
method: "POST",
statusCode: {
200: function(data) {
//OK, Welcome!
$("body").pagecontainer("change", "#welcomePage");
},
}
});
});
Can you show us your part of source code where you have this problem ?
Did you check you have this plugin in your project ?
cordova-plugin-whitelist
Also, can you throw us your HTTP response when you're sending your AJAX request to your server
It may be, something like this :
$.ajax
({
contentType: "application/json; charset=utf-8",
dataType: "json",
data: ...,
url: ...,
type: 'POST',
timeout: 5000,
success: function (data)
{
},
error: function(msg)
{
alert("Error:"+msg.status + msg.responseText);
}
});
Related
I've checked the gizillion answers to this question and for some reason I can't get this to work.
I get the error:
401 (Unauthorized)
My route is an api route guarded.
My data:
let ajaxMainTemplate = {
'mainTemplate': mainTemplate,
'templateId': templateId,
'_token': accessToken,
}
My ajax call:
$.ajax({
type: 'POST',
url:`../api/aiMainTemplate/${ajaxData.templateId}`,
data: {
_token: ajaxData._token,
ajaxData
},
success: function(response) {
console.log(response)
}
})
I've tried the above to test based on another response. I put the token outside of the ajaxData object. I get the same error. I've also attempted:
$.ajax({
type: 'POST',
url:`../api/aiMainTemplate/${ajaxData.templateId}`,
headers: { 'X-CSRF-TOKEN': ajaxData._token },
data: ajaxData,
success: function(response) {
console.log(response)
}
})
Same.
I've also confirmed the token is there by adding a console.log Any ideas what I'm doing wrong with this?
My url was behind the api protected route so I had to do an ajax call to login into it via ajax.
The credentials are in a variable ajaxData.
$.ajax({
type: 'POST',
url: 'http://127.0.0.1:8000/api/login',
data: ajaxData,
success: function(response) {
shopifyToken = response.success.token;
getListProducts(shopifyToken);
}
});
With the shopify token generated from this login it worked.
I need to to call an API with basic auth implemented. I have a form on the frontend where a user selects some options and then the values are transmitted to an API endpoint to fetch some results.
I am planning to call the API something like this ...
$.ajax({
url: WEBSERVICE_URL,
type: "GET",
dataType: "application/json; charset=utf-8",
username: "admin", // How do I HIDE this ?
password: "mypwd", // How do I HIDE this ?
processData: false,
contentType: "application/json",
success: function() {
alert("success");
},
error: function() {
alert("ERROR");
},
});
My problem is how to mask/hide the login and pwd in AJAX calls ? Is it even possible ? If not, then what are the alternate solutions ? Use a PROXY ?
Site works completely OK on other hosting. That is also shared. But doesn't work on current hosting when an Ajax post request is made. The server(not app) responds with 403.
What should I do now? I used postman and it works okay. No problem in url also.
Update:
the code for ajax request:
$.ajax({
type: "POST",
url: window.location.href.split('?')[0],
data: data,
success: function(data){
window.location = data.redirect_to;
},
error: function(data){
},
dataType: 'json'
});
The problem was "not setting" content-type in headers.
I changed the code into:
$.ajax({
type: "POST",
url: window.location.href.split('?')[0],
data: JSON.stringify(data),
success: function(data){
window.location = data.redirect_to;
},
error: function(data){
},
dataType: 'json',
headers: {
'Content-Type':'application/json'
}
});
And it worked.
I have this ajax POST code, which works directly on browser, but when i want to make a POST using the same data on Fiddler or SoapUI or using httpClient or HttpWebPost it doesn't work, always returns ERRROR. Below are the Ajax code and Fiddler. Thank you in advance.
$.ajax({
type: "POST",
url: "http://IP/address/post/something",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "text",
data:
{ message: 'testMessage', destination: '8888888888', campaign: 'UATTest', agent: 'TestingAgent'}
,
success: function (resp) {
if (resp != "ERROR") {
} else {
}
},
error: function (e) {
}
});
Update :
Does anybody know how to consume a REST API using FormParam ? how is it differ from JSON and XML ?
params:
#FormParam("destination"), #FormParam("message"), #FormParam("campaign"), #FormParam("agent")
My web service work fine but return error after send email succesfuly.
Example:
function callJsonSync(toVal, subjectVal, bodyVal) {
$.ajax({
crossDomain: true,
type: "POST",
contentType: "application/json; charset=utf-8",
url: "service.asmx/SendEmailWebService?callback=?",
data: { to: toVal, subject: subjectVal,body: bodyVal},
dataType: "jsonp",
success: function (data) {
alert("YES");
},
error: function (data) {
alert("NO");
}
});
}
All work fine, after call web service in HTML page, but always go in error!
Any reason for that?