Click here to Skip to main content
15,886,110 members

Comments by pathak vikash (Top 1 by date)

pathak vikash 12-Nov-12 6:56am View    
Plz look at the code below i have written its working fine in IE but not in Firefox


<script type="text/javascript">
var xmlHttp = null;
function CallWcfAjax() {
var val = navigator.userAgent.toLowerCase();
if (val.indexOf("msie") > -1) {
xmlHttp = new ActiveXObject("Microsoft.XmlHttp");
}
else {
xmlHttp = new XMLHttpRequest();
}

var url = "http://localhost:1912/Service1.svc/ajaxEndpoint/";
url = url + "Sum2Integers";
var body = '{"n1":';
body = body + document.getElementById("num1").value + ',"n2":';
body = body + document.getElementById("num2").value + '}';

//Send HTTP request
xmlHttp.open("POST", url, true);
//create result handler
xmlHttp.onreadystatechange = X;
xmlHttp.setRequestHeader("Content-type", "application/json");
xmlHttp.send(body);
}
function X() {
var val = navigator.userAgent.toLowerCase();
if (xmlHttp.readyState == 4)
{
var obj;
if (val.indexOf("msie") > -1) {
obj = xmlHttp.responseText;
}
else {
obj = xmlHttp.responseText;
}
var newobj = eval("(function(){return " + obj + ";})()");
alert(newobj.d);
result.innerHTML = newobj.d;
}
}

</script>