0

i use the following code

var searchUrl = config.searchUrl +'?lat='+center[0].geometry.location.lat()+'&lng='+center[0].geometry.location.lng()+'&'+Object.toQueryString(params);
jQuery.get(searchUrl, {}, function(data) {
    alert(JSON.stringify(data,null,4));
    alert(searchUrl);
});

when i use what is outputted by alert(searchUrl); which looks like this

http://website.com/Current-Build/stores/index/search/?lat=-37.5636495&lng=143.8671868&radius=30&distance_unit=km

in the browser it outputs XML like this

<results>
    <markers>
        <marker marker_label="1" location_id="953"/>
        <marker marker_label="2" location_id="952"/>
    </markers>
    <storelist><div class="store-list transparent-header">list</div></storelist>
</results>

however, alert(JSON.stringify(data,null,4)); outputs null, is there something i'm doing wrong with my request/response

NOTE: what i am trying to do is replace the original use of GDownloadUrl that was use in this script, at this point all i'm trying to do is get the response and confirm it's the same as what i am seeing in the browser

Memor-X
  • 2,870
  • 6
  • 33
  • 57
  • What does data alert to in your success function? I am wondering if the issue is that you are trying to stringify an XML string. – Jason Nov 27 '13 at 01:37
  • Does the URL you're trying to get the XML from have the same domain as the page calling it, as in are they both on the same site. – adeneo Nov 27 '13 at 01:39
  • If `data` is an XML document, you wont be able to JSON-stringify it. Try to `console.log()` it to see what it really is. – Bergi Nov 27 '13 at 01:39
  • @adeneo yeh their the same domain, the page the javascript call is made on is http://website.com/Current-Build/stores/ – Memor-X Nov 27 '13 at 01:42
  • Well, I think @Bergi nailed it, you can't stringify XML as it's not JSON, and it's probably already a string. – adeneo Nov 27 '13 at 01:43
  • @Bergi is there something else i can use other than `console.log()` as one thing that keeps coming up in the console for firefox and chrome is _The Web Console logging API (console.log, console.info, console.warn, console.error) has been disabled by a script on this page._, that's the reason why i use `JSON.stringify` as that output the contents of objects – Memor-X Nov 27 '13 at 01:44
  • What? Simply remove the script that [overwrites `console`](http://stackoverflow.com/questions/8212373/firefox-web-console-disabled) then. – Bergi Nov 27 '13 at 01:47
  • @Bergi since i'm building on Magento it took me a while to find out where to remove the script, all it's showing me in the console is [object XMLDocument] but when i parse that with `jQuery.parseXML` it then returns null, i need to see what's inside the xml just to make sure that it's what i'm expecting – Memor-X Nov 27 '13 at 03:11
  • Why not open Chromes network tab, look at the response and request sections? It should show it. F12 > Network > Find the request on the left and click on it > Click Response tab on right. – Jack Nov 27 '13 at 03:52

0 Answers0