【发布时间】:2013-07-15 13:47:11
【问题描述】:
我有一个文本框和旁边的按钮。我想通过 Jquery ajax 调用将文本框的内容发送到 webmethod 并取回相同的大写值并在警报中显示。到目前为止,我有这段代码,但它不起作用。
JAVASCRIPT:
function CallWM()
{
var name = $('#name').val();
RealCallWM(name);
}
function RealCallWM(name) {
$.ajax({
url: 'Register.aspx/UpperWM',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: { name: JSON.stringify(name) },
success: OnSuccess(response),
error: function (response) {
alert(response.responseText);
}
})
};
HTML:
Name: <input id="name" type="text" />
<input id="Button1" type="button" value="button" onclick="CallWM();"/></div>
</form>
网络方法:
[WebMethod]
public static string UpperWM(string name )
{
var msg=name.ToUpper();
return (msg);
}
【问题讨论】:
-
您收到的控制台错误消息是什么?
-
Uncaught ReferenceError: response is not defined
-
好的,正如达林所说,使用 JSON.stringify(name)
-
@Delphian 我按照 Darin 的建议进行了更改,但我收到控制台错误“未捕获的 ReferenceError:未定义响应”
-
函数“CallWM”中的“msg”有什么用,调用时没有传递值
标签: c# javascript jquery asp.net ajax