从WebMethod返回值到javascript [英] Return value from WebMethod to javascript
问题描述
我有Jquery部分,用于在c#中调用Web方法.
< script type ="text/javascript">
$(document).ready(function(){
$(''#btnLoadUserCtrl'').click(function(){
var ControlName =〜/sample.ascx";
alert(ControlName);
$ .ajax({
类型:"POST",
网址:"sample.aspx/结果",
数据:"{controlName:""+ ControlName +"''},
contentType:"application/json; charset = utf-8",
dataType:"json",
成功:功能(响应){
警报(响应);
$(''#uControl'').html(response);
},
失败:功能(msg){
alert("msasdas");
alert(msg);
$(''#uControl'').html(msg);
}
});
});
});
</script>
在此返回字符串值的webMethod中,执行功能后,它到达了jquery的成功部分,但返回了空值..
I have the Jquery part for call the web method in c#
<script type="text/javascript">
$(document).ready(function () {
$(''#btnLoadUserCtrl'').click(function () {
var ControlName = "~/sample.ascx";
alert(ControlName);
$.ajax({
type: "POST",
url: "sample.aspx/Result",
data: "{controlName:''" + ControlName + "''}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response);
$(''#uControl'').html(response);
},
failure: function (msg) {
alert("msasdas");
alert(msg);
$(''#uControl'').html(msg);
}
});
});
});
</script>
In this webMethod that returns the string value , After the excecution of function, it came to the success section of jquery, but returns null value..
推荐答案
(document) .ready(function(){
(document).ready(function () {
(``#btnLoadUserCtrl'').click(function(){
var ControlName =〜/sample.ascx";
alert(ControlName);
(''#btnLoadUserCtrl'').click(function () {
var ControlName = "~/sample.ascx";
alert(ControlName);
.ajax({
类型:"POST",
网址:"sample.aspx/结果",
数据:"{controlName:""+ ControlName +"''},
contentType:"application/json; charset = utf-8",
dataType:"json",
成功:功能(响应){
alert(response);
.ajax({
type: "POST",
url: "sample.aspx/Result",
data: "{controlName:''" + ControlName + "''}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response);
这篇关于从WebMethod返回值到javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!