Solved

How can I resolve this web service issue?

Posted on 2013-02-04
6
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 34

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
Learn how the use of a bunch of disparate tools requiring a lot of manual attention led to a series of unfortunate backup events for one company.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

710 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