javascriptasp.netwebformskmlgeneric-handler

How to pass query string values to .ashx and return a value in Javascript


I had .aspx webform wherein I would like to use javascript to show google earth from the generated kml.

I am grabbing parameters from other form and redirecting to current webform and pass parameters to a handler file which would generate a kml file based on parameters I pass to the .ashx handler file.

In the handler file, I am able to generate kmlstring along with kml filepath. I would like to return that kml path back to the .aspx webform from which I passed the parameters.

In simple words, I would like to have a function in javascript wherein I pass parameters to .ashx file and in return the .ashx file would return the generated kmlpath. Rest,I would manage with the javascript code for showing the kml in google earth.

Please anyone of you can guide me how to do it so that I can implement the same.


Solution

  • var kmlFile;
                var url = "MultipleKML_TKHH.ashx";
                if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                    XMLHttpRequestObject = new XMLHttpRequest();
                }
                else {// code for IE6, IE5
                    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
                }
    
                XMLHttpRequestObject.open("GET", url, false);
                XMLHttpRequestObject.send();
                kmlFile = XMLHttpRequestObject.responseText;
                //alert(kmlFile);