Select to view content in your preferred language

Query arcgis web service with $.ajax (jquery)

6320
4
Jump to solution
11-27-2012 10:13 AM
EricLussier
Occasional Contributor
Hi,

Does any one know how to query a arcgis web service json format with jquery $.ajax ?

I was thinking using something like this in order to test if it returns data :


[HTML]$(document).ready(function(){
$.ajax( {
  type:'Get',
  url:'http://xxx/yyy/rest/services/ppp/rrrr/MapServer/1/28?f=json',
  datatype: "jsonp",
  success:function(data) {
  alert(data);
  }
})
});[/HTML]

When trying the url in a browser the json is return...

Thanks.
1 Solution

Accepted Solutions
derekswingley1
Deactivated User

The reason I'm want to experiment with JQuery is from my understanding when using querytask you ended fetching
you results in a datatable or dgrid and because I have to deal with wcag 2.0 (accessibility standard). datagrid or dgrid are not compliant with wcag 2.0.

Using a queryTask retrieves features from a service, it doesn't do anything to display them for you. We publish samples showing how to take the results of a queryTask and display them in various ways but ultimately it's up to the developer to decide how to display features retrieved using a queryTask.


If I use querytask can I fetch the query result is table generated with JQuery?

Are you asking to take the results of a queryTask and generate a table to display them using jQuery? If so, that's possible, but it'll be up to you to code it.

Just to re-iterate, the queryTask fetches features for you. Think of it like an xhrGet or JSONP style request??? it gets some data but how that data ends up being displayed is up to you.

View solution in original post

0 Kudos
4 Replies
derekswingley1
Deactivated User
To have ArcGIS Server return JSONP, add a query string parameter named "callback". Here's an example using $.ajax:

$.ajax({
  url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query",
  data: { f: "json", where: "1=1", returnGeometry: false },
  dataType: "jsonp",
  jsonpCallback: "callback",
  success: function(response) {
    console.log("got response: ", response);
  }
});


But more importantly, why do this instead of using a queryTask from the API? Or is your app not using the JS API? If that's the case, the best place for a question like this is the AGS general forum.
0 Kudos
EricLussier
Occasional Contributor
Hi Derek,

Thanks for your answer.

The reason I'm want to experiment with JQuery is from my understanding when using querytask you ended fetching
you results in a datatable or dgrid and because I have to deal with wcag 2.0 (accessibility standard). datagrid or dgrid are not compliant with wcag 2.0.

If I use querytask can I fetch the query result is table generated with JQuery?

Thanks.
0 Kudos
derekswingley1
Deactivated User

The reason I'm want to experiment with JQuery is from my understanding when using querytask you ended fetching
you results in a datatable or dgrid and because I have to deal with wcag 2.0 (accessibility standard). datagrid or dgrid are not compliant with wcag 2.0.

Using a queryTask retrieves features from a service, it doesn't do anything to display them for you. We publish samples showing how to take the results of a queryTask and display them in various ways but ultimately it's up to the developer to decide how to display features retrieved using a queryTask.


If I use querytask can I fetch the query result is table generated with JQuery?

Are you asking to take the results of a queryTask and generate a table to display them using jQuery? If so, that's possible, but it'll be up to you to code it.

Just to re-iterate, the queryTask fetches features for you. Think of it like an xhrGet or JSONP style request??? it gets some data but how that data ends up being displayed is up to you.
0 Kudos
EricLussier
Occasional Contributor
Thanks Derek,

I will try with querytask as you proposed and see how it work.
0 Kudos