Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you call an ASHX from JavaScript?

I want to call an ASHX file and pass some query string variables from JavaScript and get the return string into a string in the JavaScript. How would I do this?

The ASHX file is already coded to response.write a string based on whatever the query strings are.

like image 795
MetaGuru Avatar asked May 26 '26 11:05

MetaGuru


1 Answers

Something like this?:

function createXMLHttpRequest() {
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }

var xmlHttpReq= createXMLHttpRequest();
xmlHttpReq.open("GET", "your.ashx?v1=1&v2=2&etc", false);
xmlHttpReq.send(null);
var yourJSString = xmlHttpReq.responseText;
like image 181
Corbin March Avatar answered May 30 '26 05:05

Corbin March