jquery.ajax jsonp question

jquery.ajax jsonp question

I am trying to make a jsonp call to bing map geocode service.  depending on what parameters i change, i either get a cross-domain error or return is not script type.  however, appending a script tag to do the call without jquery works, so i believe it's an issue with the parameters i'm configuring, i just can't figure out which one.

in the case without jquery, i have to append the callback myself as &jsonp=mycallback.  in the case of jquery, i let jquery.ajax append it for me.

  1. bingURL = 'https://dev.virtualearth.net/REST/v1/Locations?jsonp=mycallback&countryRegion='+encodeURI(country)+'&adminDistrict='+encodeURI(state_prov)+'&locality='+encodeURI(city)+'&postalCode='+encodeURI(postal_code)+'&addressLine='+encodeURI(addr_line_1)+'&includeNeighborhood=0&maxResults=1&key='+this.BING_KEY+'&output=json'
  2. // works WITHOUT jquery
  3. var script = document.createElement("script");
  4. script.setAttribute("type", "text/javascript");
  5. script.setAttribute("src", bingURL);
  6. document.body.appendChild(script); 


  1. bingURL2 = 'https://dev.virtualearth.net/REST/v1/Locations?countryRegion='+encodeURI(country)+'&adminDistrict='+encodeURI(state_prov)+'&locality='+encodeURI(city)+'&postalCode='+encodeURI(postal_code)+'&addressLine='+encodeURI(addr_line_1)+'&includeNeighborhood=0&maxResults=1&key='+this.BING_KEY+'&output=json'
  2.       $.ajax({
  3.        datatype: 'jsonp',
  4.        jsonp: 'jsonp',   // override the parm name 'callback' with this one needed by bing
  5.        type: 'GET',
  6.           crossDomain: true,
  7.           url: bingURL2
  8.       }).done(function(result) {
  9.           alert('done');
  10.       }).always(function(a,b,c,d,e) {
  11.           alert('what happened?');
  12.       });