try following code changes -
1) declare the xmlhttp variable outside the function
var xmlHttp = null;
function CallWcfAjax() {
}
2) the callback function for onreadystatechange should either be defined inline or outside the function. So, in your case, without making any changes as given in point 1 above, following will work -
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
var obj = null;
if (val.indexOf("msie") > -1) {
obj = xmlHttp.responseText;
}
else {
obj = xmlHttp.responseXML;
}
var newobj = eval("(function(){return " + obj + ";})()");
alert(newobj.d);
result.innerHTML = newobj.d;
document.getElementById("num1").value = newobj.d;
}
}
3) alternative for point 2 is to define the function outside -
var xmlHttp = null;
function CallWcfAjax() {
xmlHttp.onreadystatechange = X;
}
function X() {
}
Hope this may help you out...
Regards,
Niral Soni