none
GetBoundary error for wrong address RRS feed

  • Question

  • Hi,

    We have used https://platform.bing.com/geo/spatial/v1/public/geodata?SpatialFilter=GetBoundary to outline the boundry of the enter area. We have used following code

      _map.getCredentials(function (credentials) {
                var boundaryUrl = _baseUrl
                      + "GetBoundary('" + data + "',1,'" + regionType + "',0,0,'en','US')&$format=json&key=" + credentials;

                $.ajax({
                    url: boundaryUrl,
                    dataType: "jsonp",
                    jsonp: "jsonp",
                    type: 'POST', 
                    async: false,
                    success: function (responseText) {
                        debugger;
                        boundaryCallback(responseText);
                    },
                    error: function (e) {
                        alert(e.statusText);
                    },
                    complete:function()
                    {
                        alert("complete");
                    }

                });

    Above code works fine when correct data passed for example we pass "redmond" then it will return the result and outline the area correctly but when we passed some incorrect address like "aadsfafsdfdsf" then it did not came in errorcallback function but it throws error in jquery and show it console. If it comes in errorcallback then we will handle but it did not come in it. so it vary difficult to handle such situation.

    Can you have any idea how we handle such situation.

    Thanks!

    Balasaheb 

                      
    Thursday, February 25, 2016 1:05 PM

Answers

  • This is a HTTP GET ser if, not a post service. Try removing the following

    type: 'POST',
    async: false,

    Also verify that your code in the success fun too isn't throwing an error if there is no boundary result.


    http://rbrundritt.wordpress.com

    Thursday, February 25, 2016 1:50 PM
  • POST is not a supported way to use this service. GET is the only documented way to use this service. Can you provide the city that is failing for you? Also, ensure that you are using encodeUriComponent with the city value so that special characters don't cause issues with the URL.

    http://rbrundritt.wordpress.com

    Friday, March 4, 2016 5:40 PM
  • The GeoData API is returning a 404 error (not found) which make sense since a result wasn't found. Not sure why jQuery isn't catching this for you. Try changing you jQuery call to this:

     $.ajax({
    	 url: boundaryUrl,
    	 dataType: "jsonp",
    	 jsonp: "jsonp",
    	 type: 'GET', 
    	 async: false,
    	 success: function (responseText) {
    		 debugger;
    		 boundaryCallback(responseText);
    	 },
    	 error: function (e) {
    		 alert(e.statusText);
    	 },
    	 complete:function()
    	 {
    		 alert("complete");
    	 },
    	statusCode: {
    		404: function() {
    		  alert("page not found");
    		}
    	}
     });


    http://rbrundritt.wordpress.com

    Tuesday, March 8, 2016 12:28 AM
  • Doing some research I found that this is a limitation in jQuery. It isn't able to catch errors in cross domain requests using jsonp. The following function will be able to retrieve the request easily.

    function GetData(url, callback) {
    	var xmlHttp;
    	if (window.XMLHttpRequest) {
    		xmlHttp = new XMLHttpRequest();
    	} else if (window.ActiveXObject) {
    		try {
    			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try {
    				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e) {
    				throw (e);
    			}
    		}
    	}
    
    	xmlHttp.open("GET", url, false);
    
    	xmlHttp.onreadystatechange = function () {
    		if (xmlHttp.readyState == 4) {
    			callback(JSON.parse(xmlHttp.responseText));
    		}
    	}
    
    	xmlHttp.send();        
    }

    To use this simply call GetData('request URL', callbackFunction)


    http://rbrundritt.wordpress.com

    Friday, March 11, 2016 6:49 PM
  • Hi Ricky,

    Yes this is strange behaviour. We have checked this on Google chrome(browser)/ PC with windows 8.1(OS).

    Is anything that we are missing

    Note: For now we have added the timeout in Jquery.ajax request so at aleast it come in error callback in case of wrong address.

    $.ajax({ url: boundaryUrl, dataType: "jsonp", jsonp: "jsonp", timeout: '1000',


    Thanks

    Balasaheb

     

    Sunday, March 13, 2016 8:02 AM

All replies

  • This is a HTTP GET ser if, not a post service. Try removing the following

    type: 'POST',
    async: false,

    Also verify that your code in the success fun too isn't throwing an error if there is no boundary result.


    http://rbrundritt.wordpress.com

    Thursday, February 25, 2016 1:50 PM
  • Hi,

    Thanks for your reply.

    Previously we used Type: GET for testing we changed to POST.

    When we enter incorrect city/state/country then it throws error in console it did not goes in success or failure or complete. It throws internal error from jquery.

    Can you please check and let us know how to handle this.

    Thanks!

    Balasaheb

    Friday, February 26, 2016 4:39 AM
  • Hi,

    Any one has update for our above issue.

    Thanks!

    Balasaheb

    Tuesday, March 1, 2016 5:41 PM
  • POST is not a supported way to use this service. GET is the only documented way to use this service. Can you provide the city that is failing for you? Also, ensure that you are using encodeUriComponent with the city value so that special characters don't cause issues with the URL.

    http://rbrundritt.wordpress.com

    Friday, March 4, 2016 5:40 PM
  • Hi Ricky,

    Thanks for your response. We used GET and used some junk city like "PPPPPP". We know it do not return any boundaries but it should come in ErrorCallback function so we will handle it. The issue is when we enter such junk character in city then it did not come in ErrorCallback function  but throws error from jquery and shown in console. 

    Can you pleae let us know what should we changed in code then it will handle such situation.      

    Thanks!

    Balasaheb


    Saturday, March 5, 2016 7:24 AM
  • The GeoData API is returning a 404 error (not found) which make sense since a result wasn't found. Not sure why jQuery isn't catching this for you. Try changing you jQuery call to this:

     $.ajax({
    	 url: boundaryUrl,
    	 dataType: "jsonp",
    	 jsonp: "jsonp",
    	 type: 'GET', 
    	 async: false,
    	 success: function (responseText) {
    		 debugger;
    		 boundaryCallback(responseText);
    	 },
    	 error: function (e) {
    		 alert(e.statusText);
    	 },
    	 complete:function()
    	 {
    		 alert("complete");
    	 },
    	statusCode: {
    		404: function() {
    		  alert("page not found");
    		}
    	}
     });


    http://rbrundritt.wordpress.com

    Tuesday, March 8, 2016 12:28 AM
  • Hi Ricky,

    Thanks for your response. We tried this code but it did not resolved issue. It did not catch the error still it throws error in console.

    Can you please suggest any other way to resolve this issue.

    Thanks!

    Balasaheb

    Thursday, March 10, 2016 2:30 PM
  • Doing some research I found that this is a limitation in jQuery. It isn't able to catch errors in cross domain requests using jsonp. The following function will be able to retrieve the request easily.

    function GetData(url, callback) {
    	var xmlHttp;
    	if (window.XMLHttpRequest) {
    		xmlHttp = new XMLHttpRequest();
    	} else if (window.ActiveXObject) {
    		try {
    			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try {
    				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e) {
    				throw (e);
    			}
    		}
    	}
    
    	xmlHttp.open("GET", url, false);
    
    	xmlHttp.onreadystatechange = function () {
    		if (xmlHttp.readyState == 4) {
    			callback(JSON.parse(xmlHttp.responseText));
    		}
    	}
    
    	xmlHttp.send();        
    }

    To use this simply call GetData('request URL', callbackFunction)


    http://rbrundritt.wordpress.com

    Friday, March 11, 2016 6:49 PM
  • Hi Ricky,

    We tried above code but it throws following error.

    Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://platform.bing.com/geo/spatial/v1/public/geodata?SpatialFilter=GetBou…=json&key=Our BingmapKey'."

    When execute same using jquery then it return data. Also when we put same URL in browser then it works.

    Can you please let us know we are missing anything.

    Thanks!

    Balasaheb

    Saturday, March 12, 2016 8:59 AM
  • That's a bit crazy that the above code didn't work as that's essentially what jQuery is using under the hood. What browser/device are you using?

    http://rbrundritt.wordpress.com

    Saturday, March 12, 2016 8:08 PM
  • Hi Ricky,

    Yes this is strange behaviour. We have checked this on Google chrome(browser)/ PC with windows 8.1(OS).

    Is anything that we are missing

    Note: For now we have added the timeout in Jquery.ajax request so at aleast it come in error callback in case of wrong address.

    $.ajax({ url: boundaryUrl, dataType: "jsonp", jsonp: "jsonp", timeout: '1000',


    Thanks

    Balasaheb

     

    Sunday, March 13, 2016 8:02 AM
  • Hi Ricky,

    Can you please advise us how to resolve the above issue. We tried timeout but is did not work in all scenario.

    Waiting for your reply.

    Thanks!

    Balasaheb 

    Saturday, March 19, 2016 1:00 PM