Solved

How can I resolve this web service issue?

Posted on 2013-02-04
6
228 Views
Last Modified: 2013-02-06
I am trying to access the API url of my external client. From there I need to populate the data based on emp_id from the API webservice. while I try from my website, it says the below error.

XMLHttpRequest cannot load http://test.com/apis/sxmobile/globalapsi?emp_id=xxx. Origin http://mywebsite.com is not allowed by Access-Control-Allow-Origin.

Open in new window


Is there a way to fix ? please help me.

my ajax code,

<script>
var url_path = "http://test.com/apis/sxmobile/globalapsi?emp_id=xxx";
$.ajax({  
           type : "POST",  
           url : url_path,  
           dataType : 'text',
          // async : true,
           success :function(data){
                               alert(data);
               //eval('var data = ' + data + ';');
             // if(data != null && data != -1)
              //alert("name - " + data.name);

           } ,
           error : function(data, textStatus, errorThrown) {
               alert("error" + errorThrown);
           }
       });
</script>
 

Open in new window

0
Comment
Question by:Loganathan Natarajan
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 38851230
Shouldn't that be GET, as you pass an id with an address ? ?
 type : "GET",
0
 
LVL 33

Expert Comment

by:Slick812
ID: 38853474
greetings  logudotcom, , difficult to judge from your description, but the error message includes -

Origin http://mywebsite.com is not allowed by Access-Control-Allow-Origin.

I think that most web browsers, limit the web access points of AJAX requests to the DOMAIN of the containing web page, so I would take it that the viewed page is from -
http://mywebsite.com

so ajax can not get something from "http://test.com"
0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 38853654
@  Roads_Roads, thanks  but still i get same error if i put GET method.

@ Slick812, thanks,  yes, i think it might be cross domain access issue.  even i tried cURL way also.

Is there any way to achieve this OR we need to conclude that we cannot access anyway that API url from other ways.?
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 38856403
I seems that for ajax returns to succeed, you will have have a web address in your own DOMAIN, I have seen some examples in PHP scripts, that can access any web address (with  file_get_contents(),  fopen ( ) ,  cURL, etc. ) and get the returned data (web-page, xml , image,  json ) and then echo it back to the ajax return.
But this can be trouble-some, since the type of data returned from some XML and JSON access, can change, or return a different type-data or some ERROR or other.
I guess that's what you mean here?
although you say = "even i tried cURL way also"
which seems like you tried something before?
you really have to do the test of the access for cURL in a regular PHP page, thats NOT an AJAX return, and just display what you get back from the cURL, and when you configure cURL correctly to get the correct data from cURL, then you can move it to the AJAX return page. At least that's the way I would do it.
0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 38858076
@ Slick812, thanks
0
 
LVL 36

Author Closing Comment

by:Loganathan Natarajan
ID: 38862522
thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. Spend 30 short minutes with us to learn:   • Key questions to ask when considering a partnership to accelerate your business into the cloud • Pitfalls and mistakes other partners…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question