How to use $http post data to ssl enabled server in angularjs - javascript

$http.post(myurl, myreq).success(function(apiReply) {
if (! checkApiResponse(apiReply)){
console.log("failed to run action with error: " + apiReply.retcode + " " + apiReply.retbody)
return false
} else {
callback(apiReply)
}
}).error(function(data, status) {
var errmsg = "handle api request failed with status: "
errmsg += status + ", error response: " + data
console.log(errmsg)
ons.notification.alert({
//title: "错误",
//message: '连接服务器失败',
title: "提示",
message: "请检查您的网络环境",
buttonLabel: ['确认']
});
});
}
here is my way to post data ,when using http url,it works fine,but doesn't work when i use https url, what should i do?

Related

Why I'am always getting "Duplicate Alert" error after doing update request?

I am writing Chrome Extension for Vtiger CRM.
I need to create ability to add value for "Proposal text" field in the CRM on project page.
Here is the docs: https://www.vtiger.com/docs/rest-api-for-vtiger#/Update
How I do it:
Get the project from Vtiger API.
Change value "cf_potentials_proposaltext" in the project object.
Make POST (as required by docs) request to update Vtiger API endpoint, send updated project object
Get "duplicate alert" response..
I am absolutely sure, since I checked that I am sending the modified project object - using the console.log 'Temprorary_1' (in vtigerAddProposal) and 'Temprorary_2'(in vtigerUpdatePotential), also checked changed value in Chrome dev console in Network tab..
Here is my code:
function vtigerAddProposal() {
var temprorary_potential;
var dialog = $('#dialog');
chrome.storage.sync.get(['proposal'], function(result) {
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/retrieve',
type: 'GET',
data: {
'id': localStorage.getItem('vtiger_last_opportunity_id')
},
success: function( response ) {
temprorary_potential = response['result'];
console.log("Temprorary_1: " + JSON.stringify(temprorary_potential, null, 2));
temprorary_potential['cf_potentials_proposaltext'] = result.proposal;
vtigerUpdatePotential(temprorary_potential);
},
error: function (response) {
console.log("Failed to get opportunity from Vtiger.");
$('#dialog-inner-text').text("Vtiger: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
});
}
function vtigerUpdatePotential(data) {
var dialog = $('#dialog');
console.log("Temprorary_2: " + JSON.stringify(data, null, 2));
// Second Part
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/update',
type: 'POST',
data: {
element: JSON.stringify(data)
},
success: function( response ) {
console.log("Successfully updated Vtiger potential.")
console.log(response);
localStorage.removeItem('vtiger_last_opportunity_id'); // в случае успеха удаляем oppId
},
error: function (response) {
console.log("Failed to update potential in Vtiger.")
$('#dialog-inner-text').text("Vtiger potential wasn't update: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
}
Thank you in advance.
Problem solved by using revise https://www.vtiger.com/docs/rest-api-for-vtiger#/Revise once instead of update. Thanks to #pinaki

Error 500 post angularjs jersey

This is the problem
Here is the code which call the jersey part :
$http.post('/easyshow/api/shows/add', selectedShows).then(
function(data) {
alert("Yes");
},
function(data, status, headers, config, statusText) {
alert("No");
console.log("data : " + data + "status : " + status + "headers : " + headers +
"config : " + config + "statusText : " + statusText);
});
And finally the jersey method :
#POST
#javax.ws.rs.Path("/add")
#Consumes(MediaType.APPLICATION_JSON)
public Response addShows(List<ScannedShow> body) {
...
Response res = Response.status(Response.Status.OK) // 200
.build();
return res;
}
There is no error serverside. Everythings works, the objects are created and stored. But there is always this error 500 so I never go to the success case of the then...

Send attachment via SendGrid using Parse Cloud Code Module

I am trying to send an attachment to my email using SendGrid, in this case the attachment is of type NSData. Is there a way to send an attachment using SendGrid without having an URL or that image saved in Parse? I want to go from phone straight to email w/ attachment.
Currently the email is sending successfully, just do not have an image/attachment. Thanks in advance!
Parse.Cloud.define("sendBookRequestEmail", function(request, response) {
var Buffer = require('buffer').Buffer;
var buffer1 = new Buffer(request.params.image);
var b3 = buffer1.toString('base64');
var SendGrid = require("sendgrid");
SendGrid.initialize("username", "password");
SendGrid.sendEmail({
to: "email",
from: request.params.email,
subject: "Requesting book",
text: "Title: " + request.params.title + "\r\n" + "Author: " + request.params.author + "\r\n" + "ISBN: " + request.params.isbn + "\r\n" + "I want to: " + request.params.bookrequest + "\r\n" + "Notes: " + request.params.notes,
attachments: [request.params.image]
}, {
success: function(httpResponse) {
response.success("success");
console.log(httpResponse);
},
error: function(httpResponse) {
console.error(httpResponse);
}
});
});
The object that you were passing to the sendMail call does not have the right structure. Try something like this:
sendEmail({
to: "email",
from: request.params.email,
subject: "subject",
text: "text",
attachments: [{
content: b3, // 'Some base 64 encoded attachment content'
filename: 'some-attachment.txt',
type: 'plain/text',
disposition: 'attachment',
contentId: 'mytext'
}
],
});

Facebook story posting issue

I am setting up for posting story on facebook but I am getting following alert:
You, or this app's Open Graph Test User, must have published this action at least once.
I am getting id in the response but when I am clicking on that I am redirecting to "Page not found".
Here is my code :
FB.api(
'me/objects/appnamespace:objecttype',
'post',
{
object :{
app_id: myappId,
objectype: myurl,
title: "Sample Organization",
image: mylogo,
description: ""
}
},
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);

(#3) App must be on whitelist facebook

I'm trying to post a messsage to a wall using FB.api
My perms are: 'email, read_stream, publish_stream' and my code is:
FB.getLoginStatus(function(response){
if(response.session) {
var accessToken = response.session.access_token;
var tokenUrl = "https://graph.facebook.com/me/feed?access_token=" + accessToken + "&callback=?";
var shareUserId = document.getElementById("shareHidden").value;
var shareTxtAreaMsg = document.getElementById("shareTxtArea").value;
console.log("friends user Id: " + shareUserId + " & " + "message: " + shareTxtAreaMsg);
var data = {
message: "shareTxtAreaMsg",
display: 'iframe',
caption: "Caption",
name: "Name",
picture: 'http://someDomain.com/Dev/img/share-force-wall-img.jpg',
link: "http://www.facebook.com/pages/someapp/XXXXXXXXXXX?sk=app_XXXXXXXXXXXXXX", // Go here if user click the picture
description: "Description field",
actions: [{ name: 'action_links text!', link: 'some link' }],
}
console.log(accessToken);
FB.api(tokenUrl, 'post', data, function(response){
if (response)
{
//console.log(response);
if (response.error)
{
console.log(response.error.message);
}
else
{
if (response.id)
console.log("Posted as post_id "+response.id);
else if (response.post_id)
console.log("Posted as post_id "+response.post_id);
else
console.log("Unknown Error");
}
}
});
}
});
When when try to post the message I'm getting a "(#3) App must be on whitelist" returned. Why is this happening?
Try FB.api('/me/feed'... instead of tokenUrl because FB.api will automatically add the full url prefix.

Categories

Resources