Sending arguments to function as response - why not coming? - javascript

Recently I came up that in JS list of arguments is send to another function this way - am I wrong?
func(parameters.response.items)
Code
Request('friends.get', {fields: 'photo_100', count: 5, v: 5.95}, function(data) {
console.log(data);
Draw(data.response.items);
})
function Draw(friends) {
$('#some').html(friends[1].id);
}
The whole proyect is available on http://77.246.157.26/
Error in browser console TypeError: friends[1] is undefined
but console.log() prints all correctly and completely

Went to your site, checked it real quick.
The data from your AJAX call is getting an error..
jQuery33105943325674648605_1558658520581({"error":{"error_code":5,"error_msg":"User authorization failed: access_token was given to another ip address.","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"friends.get"},{"key":"fields","value":"photo_100"},{"key":"count","value":"5"},{"key":"v","value":"5.95"},{"key":"callback","value":"jQuery33105943325674648605_1558658520581"},{"key":"_","value":"1558658520582"}]}});
Check for error first:
Request('friends.get', {fields: 'photo_100', count: 5, v: 5.95}, function(data) {
if(!data.error) {
//console.log(data);
if(data.response.items) {
Draw(data.response.items);
} else {
console.log("Unexpected json object format.");
}
} else {
alert(data.error.error_msg);
}
});

Related

Braintree Node.js cannot get transaction.sale to work

I am building a reactjs app that among others will include Braintree Dropin UI integration. So far, I have managed to make the UI show up and send a payload to the back end. However, I cannot get the gateway.transaction.sale() part to work. Here is my code's relevant parts:
When the user clicks the pay button, this is fired:
instance.requestPaymentMethod().then(function (payload) {
console.log(payload);
completePayment(amount, payload.nonce, userId, sessionId).then((result) => {
console.log( result );
});
}).catch(function (err) {
alert(err.message);
});
And this is the code that should handle the transaction:
return gateway.transaction.sale({
amount: amount,
paymentMethodNonce: nonce,
customFields: {
session_id: sessionId,
user_id: userId
},
options: {
submitForSettlement: true
}
}).then(function (result) {
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
} else {
console.error(result.message);
}
}).catch(( error ) => {
alert(error);
});
Every time this function is fired, I get this error from catch:
TypeError: can't assign to property "success" on :not an object
Can anyone point me in the right direction?
Please note that I am not very familiar with react, node etc so my code may not be the best thing around...
Check these points:
make sure you assigned your environment to the sandbox (braintree.Environment.Sandbox);
double check (merchantId, publicKey, and privateKey).

jquery is this a valid http request

I have this http request
GET /deals/couchbaseDocument/_search
{
"query" : {
"match" : {
"amenities" : "Maids "
}
}
}
when i put it in curl, it gives me results, i want to build a web app to call that request.
what i did is removing the newlines and put the whole text in .getjson()
as this:
var query = $("#query").val();
query = query.replace(/(\r\n|\n|\r)/gm,"");
$.getJSON(query, function (results) {
alert("success");
alert(results);
})
.success(function () { alert(" second success"); })
.error(function () {
alert("error");
alert(query);
});
i kept getting the error alert, i wonder if what i did is actually what should it be done to send that request
I read this
I found that .getJson could be like this:
$.getJSON('httpURL',
{ parameter1: "parameter value", parameter2: "parameter value" })
i wonder if i should pass my json request as a parameter
in case of the whole picture** i am working on sense elasticsearch plugin
According to the documentation of jQuery's getJson, you can pass a javascript object (jQuery.getJSON() | jQuery API Documentation) so you can do something like this
var queryData = {
"query" : {
"match" : {
"amenities" : "Maids "
}
}
};
$.getJSON('httpURL', queryData)

Parse.com Failed with: ReferenceError

I am trying to run the following parse background job in Cloud Code
Parse.Cloud.job("sendAlert", function(sendAlert) {
Parse.Push.send({
data: {
"content-available": 1,
}
}, {
success: function() {
status.success("Push Worked!!!");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
}
});
});
with the intended result of, when it is run, a "transparent" (not seen by users, but seen by the app) push being sent to users.
When I run it, I get the error
Jobs:
sendAlert
E2015-02-20T19:17:22.637Z] v17: Ran job sendAlert with:
Input: {}
Failed with: ReferenceError: status is not defined
at Object.Parse.Push.send.error (main.js:12:5)
at Parse.js:2:7940
at f (Parse.js:2:6852)
at Parse.js:2:6344
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)
at c.extend.reject (Parse.js:2:6297)
at Parse.js:2:6956
at f (Parse.js:2:6852)
at Parse.js:2:7386
in the log. What am I doing wrong? Thanks, and appreciate it - total Parse novice here.
If you look for the word status in your code, you will see that you haven't declared it anywhere. A variable named status can't just come out of nowhere, so that's why you're getting a ReferenceError.
According to the documentation, the second parameter passed into the Parse.Cloud.job() callback is a JobStatus object with error and success methods, so it seems that's what you're trying to use:
// declare it here ---------v
Parse.Cloud.job("sendAlert", function(sendAlert, status) {
Parse.Push.send({
data: {
"content-available": 1,
}
}, {
success: function() {
status.success("Push Worked!!!");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
}
});
});

Posting picture to facebook Graph API using angularjs

I try to get the image upload to facebook working... Unfortunately, the facebook graph API always returns the following error:
{ error: Objectcode: 324, message: "(#324) Requires upload file", type: "OAuthException" }
It seems that the picture data is not transfered correctly. The facebook docs tell me to use a multipart/form-data upload. (See here > Publishing)
I am using angular-easyfb as a wrapper for the faceebook sdk. What's the easiest way to get this thing working? My current code is:
var sharePhoto = function() {
ezfb.api("/me/photos",
"POST",
{
"source": content,
"message": "This is a test Photo"
},
function (response) {
console.log("shared", response);
if (response && !response.error) {
/* handle the result */
}
});
};
ezfb.getLoginStatus(function(response) {
if(response.status === 'connected') {
console.log("already conntected", response);
sharePhoto();
} else {
ezfb.login(function(response) {
// Do something with response.
console.log("FB",response);
sharePhoto();
}, {scope: 'public_profile,email,user_photos,publish_actions'});
}
});
The console-log is:
already conntected {status: "connected", authResponse: Object}
shared {error: {code: 324, message: "(#324) Requires upload file", type: "OAuthException"}}
My questions are:
Whats the expected format of my variable content? How do I need to
encode it?
Do I have to manipulate the request Headers of the request? How?
Thanks a lot for your help!
Edit: Console-Log added

jquery.couchdb.js Ajax success/error not being called

I'm using jquery.couchdb.js to query my CouchDB database. The view I want to query has both map and reduce functions within. When sending the basic query as shown below:
$(document).ready(function() {
view_name = db_name+'/jobs_by_mod_stat'
options = {'group': 'true' , 'reduce': 'true' };
mod_stat = {};
$db.view(view_name , {
success: function(data) {
console.log(data)
for (i in data.rows) {
console.log(data.rows[i].value);
}
},
error: function(e) {
alert('Error loading from database: ' + e);
}
});
});
I see a sensible log for the data, indicating the query has been successful. However, changing the line:
$db.view(view_name , {
To
$db.view(view_name , options, {
I don't get a success outcome from the Ajax query, but an error message is not shown either. Firebug shows the query being sent, and the JSON data returned looks sensible:
{"rows":[
{"key":["template","completed"],"value":2},
{"key":["template","running"],"value":2},
{"key":["template","waiting"],"value":6}
]}
But the success function is not entered. Any ideas why I'm seeing this behaviour, I did wonder if it's a bug in jquery.couch.js (I have couchdb 1.1.0).
Cheers.
I've had a bit of trouble myself with the list function, until I went and looked through the source code of jquery.couch.js (the online documentation I found at http://bradley-holt.com/2011/07/couchdb-jquery-plugin-reference/ seems to be outdated).
Basically, the parameters for view and list are different, the list having an extra parameter for the options, instead of having everything under the same parameter as with views.
View:
$.couch.db('yourdb').view('couchapp/' + viewName, {
keys: ['keys here'],
success: function (data) {
}
});
List:
$.couch.db('yourdb').list('couchapp/' + listName, viewName, {
keys: ['keys here']
}, {
success: function (data) {
}
});

Categories