Domanda

Voglio chiamare un file ASHX e passare alcune variabili stringa di query da JavaScript e ottenere la stringa di ritorno in una stringa in JavaScript. Come faccio a fare questo?

Il file ASHX è già codificato per response.write una stringa in base a ciò che le stringhe di query sono.

È stato utile?

Soluzione

Qualcosa di simile ?:

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top