PDA

View Full Version : فراخوان متد با xmlhttprequest



qazxsw
پنج شنبه 07 مرداد 1389, 00:04 صبح
سلام مشکلم اینه نمیتونم با xhr به یه متد مقدار بفرستمو بخونم
به این کدها نگاه کنید

<script>
var http = false;
if (window.XMLHttpRequest) { http = new XMLHttpRequest(); }
else if (window.ActiveXObject) { http = new ActiveXObject("Microsoft.XMLHTTP"); }

var url = "Senddatainxhr.aspx/jam"; // The server-side script
function makeRequest() {
var a = document.getElementById("Text1").value;
// alert(a);
var b = document.getElementById("Text2").value;
// alert(b);
var str = "a=" + a + "&b=" + b;
// alert(str);
http.open("POST", url, true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
// alert(http.onreadystatechange);
http.onreadystatechange = handleResponse;

http.send(str);

// alert(http.onreadystatechange);
}

function handleResponse() {
if (http.readyState == 4) {
// alert(http.responseText);
result = http.responseText;
// document.getElementById("msg").innerHTML = result;
alert(result);
}
}
</script>


ASPX PAGE



public static string jam(string a,string b)
{


return a+b;
}