How to return to app from web service - ios

Edit:
I have a web service (written in PHP) to retrieve data and return the information using JSON, however I am unsure how to integrate this web service with my PhoneGap app. How do I do this?
Original question:
I have a basic app that uses a web service to retrieve data and displays the information using JSON, however I am unsure as to how to return to the app.
It is being coded in Dreamweaver using PhoneGap.
There is a form with a single input, the user selects "search" and it uses the web service to display the information.
However I cannot figure out how to go 'back' to the app as the loaded page is now on a different server.
How can this be achieved?

You should use a JQuery AJAX request. Here is an simple example:
$.ajax({
type: "POST",
url: "your-web-service-url-here.php",
//Optional data to send to the service.
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
//This is the JSON message received from the service.
alert( "Data Saved: " + msg );
});
Hope this helps.

Related

Custom activity feed notifications sent from daemon(nodejs app), not getting the data assigned to subEntityId in teams mobile client

I'm using activityFeedNotification graph api to send push notification to the users of our teams tab app from backend using nodejs. The notification is sending successfully in both teams desktop and mobile client but we're not getting the data assigned to subEntityId in mobile client(In desktop client and browser we're getting it).
We are encoding the data(object) and assigning it to the subEntityId in teams context in our nodejs application. Then in teams client, we get that data from teams context using microsoft teams sdk and redirect user to the respective page in our application based on whatever data we get in subEntityId
In desktop, deeplinking is working perfectly but in android client, we're not getting any data in subEntityId. It is just opening the homepage of our tab app but I need to redirect user to specific page based whatever data is assigned to subEntityId.
Below I've provided how we're encoding the data and assigning it to subEntityId.
Server Side:
const context = encodeURIComponent(
JSON.stringify({
"subEntityId": {
"type": "PROGRAM_PROFILE",
"program_id": "12345",
uid: uuidv4(),
}
})
);
const body = {
topic: {
source: 'text',
value: notificationTopic,
webUrl: `https://teams.microsoft.com/l/entity/${TEAMS_APP_ID}/index?context=${context}`,
},
activityType: 'commonNotification',
previewText: {
content: notificationSubtitle,
},
templateParameters: [
{
name: 'title',
value: notificationTitle,
},
],
};
const url = `https://graph.microsoft.com/v1.0/users/${userId}/teamwork/sendActivityNotification`;
await axios.post(url, body));
Client Side:
const context = await app.getContext();
console.log(context?.page?.subPageId); // getting undefined
Any kind of help is appreciated!
From the documentation:
{page.subPageId}: The developer-defined unique ID for the subpage this content points defined when generating a deep link for a specific item within the page. (Known as {subEntityId} prior to TeamsJS v.2.0.0).
You are using subEntityId on the backend but accessing subPageId on the client side.

POST data to Next.js page from external application

I have a java application which sends json data to an API via POST, what i'm trying to do is collect this data from the Next.js application to display and store in a database later. I can't figure out how to fetch this data from the Next app. currently i have the following code in the pages/api/comment and I'm calling the http://localhost:3000/api/comment from the java application
export default function handler(req, res) {
if(req.method === 'POST'){
const comment = req.body.data
const newCom = {
id: Date.now(),
text: comment,
}
comments.push(newCom)
res.status(201).json(newCom)
}
}
Can someone give me some directions please?, Thank you very much in advance.
Since Next js is working in server less architecture, you need to persist/save data some where like DB on the time of posting data, Then only we an retrieve data by get Api

How can users see the comments in a PowerPoint file via the graph-api Preview URL?

We are using Graph API to display our on-premises sharepoint files within a public facing web app. The users of the web app have complained that comments in powerpoint files are important and they cannot see these via our app (we use graph's preview url to display the file to them.)
Short of asking them to download a copy of the file to open in PowerPoint themselves (our stake holders don't want users to be able to download copies of our files) is there any way this is possible via the viewer?
If we use the webUrl property from graph-api, this opens the file on sharepoint in the Office 365 PowerPoint web app, which allows for viewing slideshow comments, but this is not going to work for users as they do not have accounts for our on premises sharepoint so will be prompted to log into our sharepoint site at this point (we do not want them to have accounts here.)
Current code (simplified) is:
<a href='#' onclick="LoadFilePreview('{sharepoint-item-id-goes-here}')>Click here to view the slideshow</a>
And the js:
function LoadFilePreview(itemId) {
var auth = $("#authToken").val();
var graphUrl = "https://graph.microsoft.com/v1.0/sites/" + siteId + "/drive/items/" + itemId + "/preview";
$.ajax({
type: "POST",
url: graphUrl,
dataType: 'json',
headers: { "Authorization": "Bearer " + auth },
accept: "application/json"
}).done(function (data) {
window.open(data.getUrl);
}).fail(function (e) {
ajaxFailed(e.status, LoadFilePreview, itemId);
});
}
I'm afraid that we can't call POST /drives/{driveId}/items/{itemId}/preview without a signed in user.
Based on driveItem: preview Permissions, Application permission(without user) is not supported.
You can post your idea on Microsoft Graph User Voice to get attention of the product group.

MVC Web Api not getting called from javascript ajax

I have a Durandal/Hot Towel test app I'm trying to wire up. I have the below ajax call but I'm getting a 404 error.
GET http/.../api/Pizza/GetPizzasByOrderId?%22a8926610-a713-494c-bb15-46f6487a01c7%22 404 (Not Found)
I can manually change the url to:
http/.../api/GetPizzasByOrderId?orderId=a8926610-a713-494c-bb15-46f6487a01c7
It works. But I would like to know why the other call isn't working or more so, why is the ajax messing the parameter up in the URL and not as data like it does with complex objects. I have a get and a save that is working just fine. The get has zero params and the save is passing a complex object in.
C# Web Api Controller:
public class PizzaController : ApiController
{
[HttpGet]
public IEnumerable<Pizza> GetPizzasByOrderId(Guid orderId)
{
return DATA.GetPizzasByOrderId(orderId);
}
}
JAVASCRIPT:
var dataCall = $.ajax(config.getPizzasByOrderIdUrl, {
data: ko.toJSON(orderId),
type: "get",
contentType: "application/json"
});
Should I just change my JavaScript code to the below and be done with it or is there a better way to talk to the Api?
var getPizzasByOrderId = function (orderId) {
return Q.when($.getJSON(config.getPizzasByOrderIdUrl + "?orderId=" + orderId));
};
You could either use the code as you have it in that last code block, or you could pass in an object in place of your orderId as in the code block below. Either way, the difference is that the orderId parameter is being named.
var dataCall = $.ajax({
url: config.getPizzasByOrderIdUrl,
type: "GET",
data: {orderId : orderId},
});
In regard to why $.ajax() works fine for your POST, you can check this out pretty easily by running these two bits of code and viewing the requests that go across the wire. I recommend using google chrome.
Load a page that has jQuery loaded
Open the developer tools and go to the console
Enter the following code snippet
$.ajax("", {
data: {orderId: 123},
type: "get",
contentType: "application/json"
});
Switch to the network tab and click on the one that ends in ?orderId=123
Notice that it does have the data appended as query string parameters
In the snippet above, replace the "get" with "post"
After you hit enter, you should see another request on the network tab of the developer tools.
Notice that when changing nothing but the request type, the data is moved from the query string to the body. As noted in the comments, WebApi will pull from the body of the request and use the model binder to populate the complex object.

Jquery ajax request on IOS using Phonegap - Ajax not working

I have a simple html login form, deployed on Xcode using phonegap framework.
When the submitLogin button is clicked, I then sent the login credentials using ajax request to verify the login.
This is my javascript function to handle the login:
function submitLoginForm (login_id, login_pass){
//here we need to communicate with the php files in the server
console.log ("debug 1 ");
$.ajax({
type: "POST",
url: "http://192.168.1.9/serverapp/loginHandler.php",
data: "login_id=" + login_id + "&login_password=" + login_pass,
success: function(loginStatus){
navigator.notification.alert ("login request successfully sent");
console.log ("debug 2");
if (loginStatus == "success"){
console.log ("debug 3 ");
location.href = "main.html";
}
else{
console.log ("debug 4 ");
location.href="index.html?errcode=1";
}
}
});
console.log ("debug 5 ");
}
After submitting the login form, I could see that the console only printed "debug 1" message. What could be wrong in this case? If the ajax request fails, it is still supposed to print the "debug 5" message, but it did not print anything and just skip the whole thing, except the first debug message.
I could access the php url from my browser, so I am sure that the problem is not with the php code. I have been trying to spend several hours with no result. Do you have any similar problem with Phonegap IOS framework, and how did you fix it?
Problem solved.
I was using an external jquery file from http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
And it appeared that the external jquery url is blocked by the ios simulator, so I have to put that url in the whitelist.
Steps:
In your XCode phonegap project, browse into Resources folder.
Go to Supporting Files directory, and edit the PhoneGap.plist file.
In the External Host list, add any external URLs that you want to
access (including the external jquery url, and any other url that you
would use in your ajax request).
I hope this will be useful for other developers who encounter the same issue as mine.

Resources