0

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.

5
  • 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. Commented Aug 18, 2015 at 7:58
  • I've tried using ajax. But looks like having problem with domain of website. Since I'm new to webservice, how to call webservice from other platform/server etc? I did search and found JSONP (JSON with Padding) to handle cross domain, but I dont think it's the answer. Commented Aug 18, 2015 at 9:19
  • Your SAP page which serves the html/javascript content initially needs to set the header("Access-Control-Allow-Origin: *"); This will allow the browser that receives the page to allow access to other domains (your php) using ajax. Commented Aug 18, 2015 at 13:56
  • Thank you @MitchDart, it works . .! Commented Aug 19, 2015 at 1:36
  • Great to hear, I will make an official answer for you. Commented Aug 19, 2015 at 6:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.