高分! 关于AJAX的问题!!

来源:百度知道 编辑:UC知道 时间:2024/05/12 05:29:21
函数
function GetVal (sv)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.open("post", "/GetDBVal.asmx/GetVal", false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send("sv=" + sv);

var val = xmlhttp.responseXML.getElementsByTagName("string").item(0).text;
return val;
}

服务
[WebMethod]
public string GetVal(string sv)
{
string s = sv + ", OK!";
return s;
}

javascritpt 中调用 alert(GetVal('AAA')) 时出错,什么原因?

因为是post,所以出错.
做form提交,进行测试看看

你这是什么玩意 乱码啊

这谁晓得是什么意思哦

麻烦知道的也告诉我一声

为什么用AAA测试呢

xmlhttp.open("post", "/GetDBVal.asmx/GetVal", false);
这句的post改成GET,或者false改成true试试.

alert(GetVal('AAA'))
客户端的语言(javascript)不能调用服务器端的函数(看起来像C#).
二者是独立的.