Jag listar en massa information (registrereade användare på en webbsida) från en databas mha ASP. kan se ut såhär:
ID1 | Login | Namn | Efternamn | aktiverad
ID2 | Login | Namn | Efternamn | inaktiverad
Nu tänkte jag göra så att man enkelt kan uppdatera inaktivera/aktivera statusen på användarna med ett ajaxanrop och har då testat med ett enkelt script jag hittat...
Jag vill skicka med användar IDt till ajaxscriptet... och anpassa mottagaren så den tar emot ... Det verkar som det är så det skall fungera redan men beriper inte hur?
jag anropar scriptet såhär:
javascript:getUsrActivate();
och resten ser ut såhär...
<script language="javascript" type="text/javascript">
function XHConn()
{
var xmlhttp, bComplete = false;
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if (!xmlhttp) return null;
this.connect = function(sURL, sMethod, sVars, fnDone)
{
if (!xmlhttp) return false;
bComplete = false;
sMethod = sMethod.toUpperCase();
try {
if (sMethod == "GET")
{
xmlhttp.open(sMethod, sURL+"?"+sVars, true);
sVars = "";
}
else
{
xmlhttp.open(sMethod, sURL, true);
xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && !bComplete)
{
bComplete = true;
fnDone(xmlhttp);
}};
xmlhttp.send(sVars);
}
catch(z) { return false; }
return true;
};
return this;
}
// doAJAXCall : Generic AJAX Handler, used with XHConn
// PageURL : the server side page we are calling
// ReqType : either POST or GET, typically POST
// PostStr : parameter passed in a query string format 'param1=foo¶m2=bar'
// FunctionName : the JS function that will handle the response
var doAJAXCall = function (PageURL, ReqType, PostStr, FunctionName) {
var myConn = new XHConn();// create the new object for doing the XMLHTTP Request
if (myConn) {// check if the browser supports it
myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName);// XMLHTTPRequest is supported browser, continue with the request
}
else {
alert("XMLHTTP not available. Try a newer/better browser, this application will not work!"); // Not support by this browser, alert the user
}
}
var getUsrActivate = function () {// launched from button click
var PostStr = "";// build up the post string when passing variables to the server side page
doAJAXCall('q_admin_users_active.asp', 'POST', '', showMessageResponse);// use the generic function to make the request
}
var showMessageResponse = function (oXML) { // The function for handling the response from the server
var response = oXML.responseText;// get the response text, into a variable
document.getElementById("responseDiv").innerHTML = response;// update the Div to show the result from the server
};
</script>