Consume PHP web service with javascript (client side programming) Sharepoint - javascript

I'm not familiar with Web Services. My company wants to integrate SharePoint 2013 to SAP. My company (right now) only allow us to develop SharePoint app using client side programming (JavaScript).
We already have some PHP application connect to SAP through RFC, so my idea is creating PHP web service and consume it from JavaScript (SharePoint).
My Question :
1. Can we do that?
2. Is there another ways to integrate SP to SAP with Client Side Programming?
I tried simple JavaScript calling php function (not a webservice) using Ajax below, but having error (alert:error2).
$.ajax({
type : "POST",
url : "http://10.15.5.150/testapp/test_ws",
data : "id=1",
cache : false,
success : function(data){
var data = eval('('+data+')');
if(data.success){
alert(data.msg);
}else{
alert('error');
}
},
error: function(data){
alert('error2');
}
});
Thanks.

Consuming a PHP web service is most definitely possible with having javascript as a client. It is especially simple if you can make use of the JQuery library in javascript. This Library will give you simple tools you need to create ajax requests to the PHP service.
If the PHP Web Service is hosted on another domain, (Other than the SharePoint domain) the SharePoint server providing the Javascript needs to include the following header.
"Access-Control-Allow-Origin: <domain-of-php>"
Note: the domain can also be * for all domains.
This header will allow the browser to connect to other domains other than the original domain.

Related

How to call a function written in C with axios?

I’ve used a microcontroller to develop the embedded web server and I’m not sure if I can download an Apache or any other server into my controller.
However, I’ve successfully implemented an HTTP interface and have been hosting web pages and handling & parsing the POST request data/payload at the embedded web server side.
The issue is coming when the web page contains any form type data to be submitted.
I receive the value(s) entered by the user on the web page but I'm not able to display the data properly on the web page sent by the embedded server.
That’s where there’s a major issue in linking C (freeRTOS) code (server side) and JS (client side).
How can a JS web client pull data from embedded web server (in freeRTOS) given that I have a successful HTTP connection established with the web page and I'm also able to host pages as mentioned above?
Currently I'm using axios but unable to figure out how to call a C function in the URL? As it's not possible to code in C without a function.
axios({
method: 'post',
url: 'getStatus.c',
data: sampleData,
headers: {'Content-Type': 'multipart/form-data' }
})
.then(function (response) {
console.log(response);
})
You cannot directly call a function in uncompiled C source file.
axios is a client side ( JS lib ) technology. Any server side program that you want to interact with axios must implement some sort of HTTP interface.
If you must use C to achieve something like that:
Implement a CGI interface in C
CGI program can as simple as something like this ( Handling POST request is bit more difficult ):
#include <stdio.h>
int main()
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<body>\n");
printf("<h1>Hello there!</h1>\n");
printf("</body>\n");
printf("</html>\n");
return 0;
}
You can access POST request data the following way:
len_ = getenv("CONTENT_LENGTH");
len = strtol(len_, NULL, 10);
postdata = malloc(len + 1);
if (!postdata) { /* handle error or */ exit(EXIT_FAILURE); }
fgets(postdata, len + 1, stdin);
/* work with postdata */
free(postdata);
How to retrieve form "POST" data via cgi-bin program written in C
More on CGI C programs: http://jkorpela.fi/forms/cgic.html
Consider using libcgi http://libcgi.sourceforge.net for CGI C programs.
Compile the CGI program.
Use Apache2 or Nginx to serve the CGI "script" in this case the compiled binary.
If using C is not a priority:
I would recommend to use a high level language which is more suitable for web development. Python / PHP / C# / Java / etc..

Communication between JavaScript and WCF Service Library (WCF Test Client)

there is a web service (WCF Service Library) when I debug the web service project (in Visual Studio) "Test Client WCF" is launched (so I guess its hosted via the Test Client). I have a web service method called "Test" which returns string. When I "call" that method with the Test Client WCF - it works.
When I want to use browser as a client. I go to http://localhost:9001/Name/WebService/WebAPI and I see the web service (xml with some info about methods). And now I want to use JavaScript to call that Test method.
I created a client similar to this https://stackoverflow.com/a/11404133 and I replace the sr variable (SOAP request) with a request, which is in XML part of the Test method in the "Test Client WCF" and for url I chose http://localhost:9001/Name/WebService/WebAPI . I tried that JavaScript client, but I got some client error -
content-type 'text-xml' is invalid, server wanted
'application/soap+xml; charset=utf-8'
(unfortunately right now I can't get to the web service, so I don’t know a number of the error and exact message, but there was no other information, beside the content-type). So I changed the request header to 'application/soap+xml; charset=utf-8', but then I got error – that tells me:
The message cannot be processed at the receiver, due to an
AddressFilter mismatch at the EndpointDispatcher. Check that the
sender and receiver's EndpointAddresses agree
(Or something like that - I had to translated it to english)
I also tried the "JavaScript client" with an existing service, that I found on the internet and with text/xml content-type. And it works fine.
Please do you have any advice - how to call the Test method with JavaScript? Thanks.
The service invocated in Javascript is called Restful style service. WCF is able to create a Restful style service too. But we need to set up some kinds of additional configuration. The service is hosting in IIS express when we test the service in Visual Studio. It uses the default binding configuration to host the service(BasicHttpBinding), called SOAP web service. The universal way to invocate the service is taking advantage of using service proxy class, that is what the WCFTestClient do.
If we want to invocate the service by using JavaScript, here is a simple demo, wish it is useful to you. Please be aware that the project template is WCF Service Application instead of Service Library project.
https://stackoverflow.com/questions/56873239/how-to-fix-err-aborted-400-bad-request-error-with-jquery-call-to-c-sharp-wcf/56879896#56879896
Feel free to let me know if there is something I can help with.

How to implement recaptcha in odoo

We are using odoo 12 online for enterprises.
We would like to protect our forms using google recaptcha.
How can we implement google recaptcha? If possible a full example how to implement it.
We would prefer recaptcha v3 but if not possible a v2 implementation is fine.
When I try to search online for implementation of google recaptcha there's almost every time a .php file included. Our pages are loaded with QWeb view types and php isn't supported.
Is it possible to implement without php? We could definitely use html and javascript and probably python, is it possible to do with only these? If it's possible we would like to do it with only javascript and html but I'm assuming that's not the case.
Is there any other form protection we could implement using only html and javascript?
Google reCAPTCHA v3 in Python
You need to install reCAPTCHA on the frontend and implement the verification on the backend. At the bottom of the post, I linked the official Google reCAPTCHA documentation.
Frontend Integration
<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
...
});
});
</script>
The frontend just needs to:
Load the JavaScript api with your sitekey
Call grecaptcha.execute on an action or when the page loads
Send the token to your backend with the request to verify
Backend Integration
The verification of the token is the same as in reCAPTCHA v2. When the user submits the form on your site, you get the POST parameter g-recaptcha-response. You need to make a POST request to the Google reCAPTCHA service with following parameters. You can take your HTTP request framework of your choice.
URL: https://www.google.com/recaptcha/api/siteverify
POST Parameter Description
secret Required. The shared key between your site and reCAPTCHA.
response Required. The user response token provided by the reCAPTCHA client-side integration on your site.
remoteip Optional. The user's IP address.
Then you get a JSON response from the service and if the request failed, you can handle further actions on the backend.
{
"success": true|false,
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
"hostname": string, // the hostname of the site where the reCAPTCHA was solved
"error-codes": [...] // optional
}
Sources
Google | reCAPTCHA Installation
Google | reCAPTCHA Verification
Hope this will helps, you can get an idea from odoo forum.

sharePoint online count unread message from office365

As part of a project whose aim is to notably improve the visual side of a SharePoint Online site, I'm a bit stuck. On the home page in the left banner, users want to see the number of unread messages they have in Office365.
I created an area in the master page to put the result in. I thought the Rest API used to do this :
$.ajax ({
type: "GET",
url: " https://outlook.office365.com/ews/odata/Me/Folders/Inbox",
dataType : "json",
success : function (resp) {
// count unread messages
},
error : function (e) {
alert (' Error121212 :' + JSON.stringify (e));
}
})
Unfortunately I get an error like cross domain. I tried with JSONP but it does not work either (uncaught syntax error unexpected token).
Can you please tell me if this is a good practice? I feel that it anyways I must find a technic for authentication. (In the case of JSONP I have a popup that asks me authentication and then problem occurs on callback apparently)...
I want to avoid developing a type requiring a typical deployment Wsp...
Thank you in advance for your help.
Your URL for the ajax request seems incorrect. The URL for getting the inbox messages via the API is: https://outlook.office365.com/api/v1.0/me/folders/inbox/messages
Once you get the response, you can count the number of objects with the IsRead property set to false using a simple for loop and display that count.
The issue here is related to CORS and how browsers refuse to handle cross-domain requests. To get around this, typically you would either
Change the response header on the remote server - not an option here
Use some sort of proxy to handle the requests - here's where SharePoint apps come in.
I know you stipulated that you want to avoid using a WSP style deployment but there simply isn't a way around it, you have to use the SharePoint App Model
This article goes a long way to answer your question, but for completion the basic steps are as follows
Create a SharePoint hosted app in Visual Studio
In the App Manifest, you need to define the trust relationship with the remote host (in this case the host of outlook.office365.com) using the AppManifest section
Use SP.RequestExecutor.executor to make the request on your behalf

Strange problem with jQuery ajax post

I have very strange problem and that problem occurs very rarely and that too in our production env.
The production env. setup is,
Apache Web Server as front layer
Apache Tomcat 6.0 as application server (liked with Apache Web server via mod_jk)
I have custom made Ajax based RPC component where we use jQuery for ajax calling. The data is communicated using POST method.
The client side data (javascript objects) are sent to server in JSON format and on server side they are deserialized into java objects.
The RPC call is executed by providing following information,
var jsonParamObj = new Object();
jsonParamObj.param0 = objParam0;
var params = new Object();
params.**jsontext**=**toJsonString**(jsonParamObj);
where jsontext contains the real data to be transmitted. I am using toJsonString javascript function available as open source json script (previously used JSON.stringify but had same problem).
Following is the jQuery call,
$.ajax({async:async,
data:params,
dataType:"json",
type:"POST",
url:this.ajaxAction+qs,
contentType:"application/x-www-form-urlencoded; charset=UTF-8",
error:function (XMLHttpRequest, textStatus, errorThrown)
{
alert('Connectivity Issue : '+textStatus + ' Error : '+errorThrown + ' Response : '+XMLHttpRequest.responseText);
},
success:function(jsonobj){
if(jsonobj.JSON.ajaxSysError)
{
alert(jsonobj.JSON.ajaxSysError.message);
return;
}
// do other work
}
});
Now the problem is sometimes whatever data sent in forms of params do not reach to server (not to apache as well as tomcat) I have enabled maximum level of verbosity in logs however whatever data it sends through query string (see qs) reaches server.
The client browser is IE 7 (Windows XP Media Edition).
Can you put some thoughts that would help me in debug this issue.
Thanks for reading this long question.
Jatan
Install Fiddler and look at the HTTP request that IE is sending.
Also, put the ajax call in a try/catch block and check whether you're getting any Javascript errors.

Categories

Resources