Red de conocimiento informático - Material del sitio web - Cómo solicitar HTTP usando JS

Cómo solicitar HTTP usando JS

De hecho, puedes leerlo completo usando el método ajax de jquery.

var?result?=?false; var?thenow?=?new?Date();

$.ajax({ tipo: "POST", url: "Esta es la ruta relativa del archivo php ?Time =" thenow.getMillisegundos() "M " thenow.getSeconds() "", datos: {id: id},? éxito: función(datos){ }

});

Si no usa jquery var?xmlHttps?=?new?Array(10);? var?e; var?EndHtml=false; //crear objeto XMLHTTP function?getXMLHTTPObj() { var?C? =?null; prueba {

C?=?new?ActiveXObject("Microsoft.XMLHTTP"); captura(e) {

prueba

{

C?=?new?ActiveXObject("Msxml2.XMLHTTP");?

}

catch(sc)

{

C?=?null;

} } if(? !C?amp;amp;?typeof?XMLHttpRequest?! =?" undefinido"?) {

C ?=?new?XMLHttpRequest(); } retorno?C; } función?GetDetail(userid,id)? {? document.getElementById(id).innerHTML?=?""; >

xmlHttps[id]=false;

xmlHttps[id]=?getXMLHTTPObj();

if(?xmlHttps[id]?)

{ var? /Ajax.aspx?action=" id "amp;userid="? ?escape(userid) "amp;date=" new?Date().getTime();

xmlHttps[ id].open ("get",?realUrl,?true); xmlHttps[id].onreadystatechange?=?function(){updatePage(id,xmlHttps[id])};?

// enviar solicitud

xmlHttps[id].send(null);

//?xmlHttps.abort();;

}

else

p>

{ document.getElementById(id) .innerHTML?=?" lt; font?color=#ff0000gt; × lt; / fontgt; Su navegador no admite " <; /p>

} } catch?(e) { document.getElementById(id).innerHTML?=?" lt;font?color=#ff0000gt;×lt;/fontgt;?Se produjo una excepción"; /p>