I build my software with Jquery mobile. In my code I use Ajax JSONP calls to retrieve information from a server. This gives no problem when testing in my browser. With phonegap / cordova I have generated an Android APK and a Windows XAP file. The Android build gives also a success, but when running on a Windows phone I get a 404 error.
Does anybody have a clue what could be the reason for this 404 error; could it have to do with permissions?
Many thanks in advance.
In the config.xml I have added: access origin="*"
The Ajax call looks like:
function retrieveProvincies()
{
$.ajax({url: 'http://www.itclubsupport.nl/test/AppPHPtest/AppIngang.php',
method: 'POST',
data: {
indicatieTestenApp: 'yes',
soortRequest: 'retrieveProvincies',
klantnaam: 'klantITclubsupport'
},
dataType: "jsonp",
success: function (response) {
alert('works!');
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
alert('Status ' + jqXHR.status + ' received when retrieving provincies. Error: '
+ textStatus + '; ' + errorThrown);
}
})
}
Related
My code can get an auth2.0 token...but the examples I've found don't show the final piece of taking a GET, provided here, and turning it into a working request.
Here is the specific URL from that link:
GET https://www.googleapis.com/drive/v3/files/fileId
Here is my AJAX call with the attempt at getting the token (that works) into a hardcoded fileId that I know my Google account has access to.
$.ajax({
type: "GET",
beforeSend: function(request) {
request.setRequestHeader("Authorization", "Bearer" + token);
},
// url: "https://www.googleapis.com/drive/v2/files/18qxc3YgnQ_Yg8n4Q18WCZahE9EPtOZWhoKJuAx6SEHI/permissions",
url: "https://www.googleapis.com/drive/v3/files/18qxc3YgnQ_Yg8n4Q18WCZahE9EPtOZWhoKJuAx6SEHI",
dataType: 'application/json',
processData: true,
success: function(msg) {
console.log('Got File Metadata: ' + msg) + console.log(msg);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('Error: ' + errorThrown + ' / ' + textStatus) + console.log(jqXHR);
}
});
I don't understand how to include the token and the pages and pages of Google documentation do not include any examples of going this route.
I get "invalid credential" errors in the server response.
I don't want to use GAPI because I ran into invalid cookie issues running locally and my code is in a Chrome Extension and it isn't clear whether that approach will work there.
Thank you for any help or direction.
In your code, this line:
request.setRequestHeader("Authorization", "Bearer" + token);
You should have a space after Bearer
request.setRequestHeader("Authorization", "Bearer " + token);
I have this AJAX call to my Web Core API;
saveProperty = function (url, data, callback, errorCallback) {
$.ajax({
async: true,
type: "Post",
url: url,
data: data,
contentType: "application/json",
dataType: "text"
})
.done(callback)
//.fail(errorCallback);
.fail(function (jqXHR, textStatus, errorThrown) {
alert("Something went wrong: " + textStatus + " " + errorThrown);
errorCallback();
});
}
Sometimes it works, more often it does not.
When I use Fiddler and it works, I see
And when it doesn't I see;
EDIT - I can be more helpful now in describing this problem.
if I have Fiddler up and running before I lanch the aplication in development, I do not get this bug.
Otherwise I do get this bug.
Why is that? I would love to know.
The error is HTTP Error 401.2 - Unauthorized
Why would this happen with the same code?
I am making hybrid application using IBM Worklight.
In my windows phone 8.1, when I am running this application, ajax calls returns readyState 4, status 404.
Am I doing something wrong? Any help would be greatly appreciated.
Screen Shot of Project Files Hierarchy Here
AJAX Request Code:
$.ajax({
type: "get",
url: "index.html",
success: function (data) { alert("success" + JSON.stringify(data)); },
error: function (error) { alert("error" + JSON.stringify(error));}
});
You have to append "www/default" before page name, because In windows phone MainPage.xaml is loaded first, which is in root directory. And $.ajax will search from root directory and hence you have to give path as below.
$.ajax({
type: "get",
url: "www/default/index.html",
success: function (data) { alert("success" + JSON.stringify(data)); },
error: function (error) { alert("error" + JSON.stringify(error));}
});
If your application have too many $.ajax or $.get and you don't want to modify each and every request you can use following global ajax settings when your application starts.
$.ajaxSetup({
beforeSend: function (jqXHR, settings) {
settings.url = "www/default/" + settings.url;
}
});
I'm having troubles with ajax. my code runs well, but then, it always goes to success.
dataLogin = 'mail=' + $('#login_mail').val() + '&pass=' + $('#login_password').val() + '&on=' + manter_ligado;
$.ajax({ url: 'modules/login.php?' + dataLogin,
type: 'POST',
//data: dataLogin,
data : {
mail : $('#login_mail').val(),
pass : $('#login_password').val(),
on : manter_ligado
},
success: function(data) {
alert(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
can anyone help me with this?
Also, I'm using sublime to code, and it gives me some errors on the ajax, but I can't seem to correct them, it might help knowing this
Also, I know that the php works, because I can make the login on the website, but the problem I have is when the user/pass is incorrect
Make sure the server is returning an error code of 500.
In the php.ini file, make sure displayErrors is set to Off
To get the ajax to hit the failure function, you may need to throw an error when one occurs in your PHP
Is there way to handle AJAX Origin errors from Chrome's extensions ?
Denying load of
chrome-extension://kldbdjcbjohfhddpicldkbifbkcdanid/data.json.
Resources must be listed in the web_accessible_resources manifest key
in order to be loaded by pages outside the extension.
I tried this:
$.ajax({
url: 'chrome-extension://kldbdjcbjohfhddpicldkbifbkcdanid/data.json',
datatype: 'json',
success: function(xhr) {
alert('ok');
},
erro r: function(xhr, status, err) {
alert('status: ' + xhr.status + ' - ' + err);
}
});
but got nothing in variables. error status is "0", error message is empty.
You can try using the jsonp format. This often gets around cross-origin errors.
$.ajax({
url: 'chrome-extension://kldbdjcbjohfhddpicldkbifbkcdanid/data.json',
datatype: 'jsonp',
success: function(xhr) {
alert('ok');
},
erro r: function(xhr, status, err) {
alert('status: ' + xhr.status + ' - ' + err);
}
});
Sounds like you are attempting to load this resource from a content script, based on the error.
You have to explicitly add either the individual extension resources, or patterns that match your extension resources, in the manifest via web_accessible_resources. Your error message states this is the solution.
Once you've done this, you can construct the URL using chrome.extension.getURL(resourcePath).
Here's an excerpt from my manifest:
"web_accessible_resources" : [
"*.html"
]
And here's the code I'm using to request my HTML template file:
var url = chrome.extension.getURL("template.html");
$.get(url,function(data, textStatus, jqXHR){
console.log("Got the template!");
console.log(data);
},"html");