In my Blackberry app using phonegap, I have Facebook share feature and I am doing this using phonegap's childbrowser. After I login to Facebook, access_token is to be requeted. For this I am using the following code :
$.ajax({
url:'https://graph.facebook.com/oauth/access_token?client_id='+my_client_id+'&client_secret='+my_secret+'&redirect_uri=http://www.facebook.com/connect/login_success.html',
data: {},
dataType: 'text',
type: 'POST',
success: function(data, status){
alert(22);
// We store our token in a localStorage Item called facebook_token
localStorage.setItem(facebook_token, data.split("=")[1]);
window.plugins.childBrowser.close();
app.init();
},
error: function(error) {
alert("fail"+error['message']);
window.plugins.childBrowser.close();
}
});
But the control is not going inside the success section instead it is going inside error section. What may be the problem. When I try to find the error using "alert("fail"+error['message']);", it is coming as undefined. Please help me to resolve this.
Related
Good day,
We are building a project that uses WordPress for the marketing(normal pages, blogs, etc) and angular for the more functional side of this project. My current issue is we use the wordpress side for registration, subscribing to newsletter, and logging in. Newsletter and registration is now okay but I have a problem with the login. I'm using a custom bootstrap form, and use ajax. I'm given an api to get the login token first, then include that token in post for logging in.
This is currently what I got in my scripts.js:
$('#login-button').click(function(event) {
event.preventDefault();
// extracting the token
$.get("https://sample-dummy-url/Account/Loginwp", function(data, status){
// setting the token to loginToken variable to include in logging in
loginToken = $(data).find("input[name='__RequestVerificationToken']").val();
// checking if token is extracted
console.log(loginToken);
});
// I know this will be empty outside of the function of getting the token, but this is my current idea
console.log(loginToken);
// setting the variable to pass for logging in
let login = {
Username: $('#loginUsername').val(),
Password: $('#loginPassword').val(),
button: 'login',
// this is where I supposedly assign the extracted token but I know this is empty
__RequestVerificationToken: loginToken,
RememberLogin: $('#loginRememberMe').is(":checked"),
}
// ajax for logging in
$.ajax({
url: 'https://sample-dummy-url/Account/Login',
headers: {
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json',
'Content-Type': 'application/json; charset=UTF-8'
},
type: 'POST',
dataType: 'json',
data: JSON.stringify(login),
success: function(msg, textStatus, jqXHR) {
console.log("logged in");
},
error: function(msg, textStatus, jqXHR) {
console.log(msg);
console.log(textStatus);
console.log(jqXHR);
},
});
});
My idea was only to invoke the getting of token when login button is clicked, then extract the token to a variable so I could include it in the login object so that when I use another ajax to post for login. I know this might be not the best/ideal/practical implementation, but I am truly open for suggestions & enlightenment of the proper way of doing it.
Thank you for any help.
I am trying to connect a JavaScript client with a TFS 2015 API to get some information and save it in my SQL Database, but I am having challenges establishing this connection with JavaScript. They are using Windows authorization.
I used this code but it didn't work:
$.ajax({
url: 'https://tfs........',
type: 'GET',
dataType: 'json',
xhrFields: {
withCredentials: true
}
})
.done(function (data) {
console.log(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
});
Can anyone help me please?
Refer to these 2 threads(one, two), check if the Access-Control-Allow-Origin is a wildcard like '*'. This is not allowed.
Update:
Refer to this case who have similar issue with you: connecting to TFS using windows auth in electron app.
You could create a login in page, and store username and password in cookies. Then use httpntlm to do this request.
I have a problem with getting number of shares of my custom url. Im trying this code:
$.ajax({
type: "POST",
url: "http://graph.facebook.com/https://www.myurl.com/somelink/?callback=?",
processData: true,
contentType: 'application/json',
success: function(r){
var fbjson = JSON.stringify(r);
console.log(fbjson);
}
});
I've tried also:
$.getJSON('http://graph.facebook.com/https://www.myurl.com/somelink/?callback=?'), function (data) {
fbjson = JSON.stringify(fbjson);
console.log(fbjson);
};
When I paste url into browser I recieving JSON with all needed information, but when I am using $.ajax etc. I am recieving totaly different json or some error that I should use XMLHttpRequest or some other serwer status information. Important knowladge may be that I am using https://.
Anyone know how to correctly get FB share count for custom URL ?
PS Be understanding for me, this are my first steps in JS, thanks :)
For the json might be cooke issue. your browser have cookie for that URL but in ajax you need to pass that cookie !
Why you are counting share count manually ?
There is lots of share tools is available for fee !
example : http://js-socials.com/
I think this plugin will give you what you need !
Thanks
I've solve it. This script work correctly ;)
(function fbcount() {
var token = 'token here',
url = 'url here';
$.ajax({
url: 'https://graph.facebook.com/v2.7/',
dataType: 'jsonp',
type: 'GET',
data: {access_token: token, id: url},
success: function(data){
$('.facebook-scount').append(data.share.share_count);
},
error: function(data){
}
});
})();
Thanks!
I have an Ajax request that is sent over to a file to grab information and return JSON.
Here is my request example:
$.ajax({
url: "admin/actions/ifp_get_events.php",
type: "post",
dataType: "json",
data:
{
'elevation_name' : 'global',
'function' : 'elevation_restrictions_events',
'parent_id' : d.ifp_id
},
success: function(data){
......do stuff
},
error:function(){
alert("error occured, please try again.");
}
});
Now I've been developing using Google Chrome and it works perfect but when I go to try this in Firefox or IE I am getting the following error:
The alert of coarse is being triggered and I have a response text of:
responseText:"
{
"status":"error",
"message":"You have been logged out due to inactivity."
}
{"status":"found","code":1,"original_request":
{"elevation_name":"global","function":"elevation_restrictions_events","parent_id":"26"},"data_retrieved":[{"evt_for":"Game Room","evt_restriction":"","evt_select_ability":"hide","evt_active_ability":"disable"},{"evt_for":"Bedroom 5 w\/ Bath 5","evt_restriction":"Craftsman Entry, Kitchen","evt_select_ability":"show","evt_active_ability":"enable"}]}"
Note that once the error message was given the new status section is the correct response I needed. I am just uncertain as to why this is happening in Firefox and IE?
Suggestions, thoughts?
If you need any more information please ask me.
Browser sessions aren't shared across browsers. In your case, you were logged in Chrome and hence the code was working as expected.
However, when trying out with FF and IE, you weren't logged in and hence the output was different.
add this line :
beforeSend: function (xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
},
after your data.
Since the valid csrf token is not going its logging you out of the site.
I am trying to login to a website using a known username and password and to get some data displayed from the site for a specific user account on that website. I am using jQuery and Ajax for this purpose. This is my code:
$.ajax({
async: false,
cache: false,
type: 'POST',
dataType: 'json', // json...just for example sake
data: ({
'login_username': username,
'secretkey': password
}),
url: 'https://mail.someserver.com/src/redirect.php',
success: function (data) {
alert("SUCCESS!")
if (data === '1') { // server returns a "1" for success
// success!
// do whatever you need to do
} else {
// fail!
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// something went wrong with the request
alert("Failed!");
}
});
I've already made my search around the web and I know that browsers do not permit cross server ajax calls to prevent security issues, but I've already tried to use "jsonp" as dataType to no avail :(
So, what am I doing wrong?
Be sure that your url is not breaking the same origin policy -- that is, the request coming from the client cannot request data from a server from a different domain (there are exceptions to this rule, namingly CORS, but that requires that you make changes to the server/application you're talking to).
The solution to your problem would be to make the request from some server-side script, then in turn having your client application query that script, based on the same machine that's serving the application to the web.
My fault isn't at the code above, my fault was that in my manifest file (I am building a Google Chrome extension) I didn't have set proper permissions (https://*).
Sorry for the frustration!