user1453857
user1453857

Reputation: 207

jQuery get data from REST service

i have implemented REST service which is hosted on address http://localhost:8080/rest/adrestresource/1.0/activedirectory/findgroups%[email protected]%20pwds%20localhost . This service is visible and accesible (i can get xml from it using web browsers), but i am no able to write simple jquery script which will get data and displays it. My code:

$.ajax({                     
                      url: "http://localhost:8080/rest/adrestresource/1.0/activedirectory/findgroups%[email protected]%20Bezhesla1%20localhost",
                       //url:  'http://api.geonames.org/astergdem?lat=50.01&lng=10.2&username=demo&style=full&type=XML',
                      type: 'GET',
                      dataType: 'xml',
                      success: function(xml){
                              alert('success');                                                           
                        }



                    });

When i change address to another rest service, alert popup appears (which means that problem is in REST service path). Any ideas what is wrong? :)

REST service is implemented as Atlassian JIRA plugin deployed on local jira instance :)

Upvotes: 0

Views: 1074

Answers (2)

Balint Bako
Balint Bako

Reputation: 2560

In order to enable cross-domain XHR requests put jQuery.support.cors = true; in a the js code. I usually add it to a <script> block right before </body>.

Upvotes: 1

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

Try data parameters in this, you can't directly pass the parameters in URL you have to use data attribute of jQuery ajax request.

$.ajax({
            type: 'POST',
            url: '"http://localhost:8080/rest/adrestresource/1.0/activedirectory/findgroups',
            data: {argu1: 'data1', argu2: 'data2', argu3: 'data3'},
            contentType: "xml",
            success: function(xml){
                  alert('success');                                                           
            });
           }

        })

Upvotes: 1

Related Questions