Data Access - Plain Text Sample not working

595
4
04-04-2011 12:39 PM
CarmenDurham
Occasional Contributor II
Hello all,

I need to grab a text file that is stored at the same level as the javascript/html app and process it for lat-lon.  I have something similar that works with a ArcGIS Extension for Google API but need to really use the ESRI Community Maps service (as our data is included) so I am trying to re-create with just the ArcGIS API for JS.  Amazing how different the two are.

Anyway, I cannot get this sample to work and display my textfile.  I have only changed the url (tried various versions of the path), removed the proxy line of code and set the useProxy: false (or removed it altogether with one try).  The text file is sitting at the same level in the dir. structure as the .html.  Should not have a proxy issue.

In IE, I get " Member not found" error in the Content box.  In Fire fox, I just get "[Object Event]" in the Content box.  I never get the contents of the text file.

It is here temporarily:

http://gis.greenvillesc.gov/testonly/

You can see the text file itself at: http://gis.greenvillesc.gov/testonly/testurl.txt

In the Google API based app, I used gXmlHttp to load the text file.

Any help will be appreciated.

Thanks,
Carmen
0 Kudos
4 Replies
MarbryHardin
New Contributor
It looks like it's returning an object rather than say just the text of the file.  Do you need to reference it similar to this perhaps?

dojo.byId("content").value = response.value;
0 Kudos
derekswingley1
Frequent Contributor
The simple solution would be to switch to dojo.xhrGet (literally replace "esri.request" with "dojo.xhrGet" and your code should work).

The problem has to do with how esri.request() works. When you use esri.request() to do a GET, you're actually doing a dojo.io.script.get(). This function always expects javascript/json and ignores the "handleAs" parameter. When you use esri.request() to do a POST(usually via a proxy), you do are really doing a dojo.xhrPost() which does support a "handleAs" parameter. This is what the sample you referenced is doing- a POST via esri.request() which goes through a proxy to retrieve the text file used in the example.
0 Kudos
CarmenDurham
Occasional Contributor II
Derek,

Thank you!  That worked. 

So, based on Derek's information, here is the portion that I changed.  I replaced esri.request with dojo.xhrGet and totally removed the {useProxy: true}  parameter. 

      var requestHandle = dojo.xhrGet({
        url: url.path,
        content: url.query,
        handleAs: "text",
        load: requestSucceeded,
        error: requestFailed
      });


Thanks again - I have been primarily coding with Flex API so the javascript API is new territory -- you saved me a lot of time.

Carmen
0 Kudos
derekswingley1
Frequent Contributor
Glad to help!
0 Kudos