Ajax调用不起作用。任何人都可以帮助我...... [英] Ajax calling is not working. Any one may help me...

查看:69
本文介绍了Ajax调用不起作用。任何人都可以帮助我......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net页面上我使用的代码如下:



 $(' 。del')。click( function (event){
var parentID = { CategoryID :$( this )。nearest(' li').attr(' id')};
parentID = JSON .stringify(parentID);

alert(' 在ajax调用'之前);
$ .ajax({
类型: POST
url: MasterService.asmx / RemoveCategory
data:parentID,
contentType: application / json; charset = utf-8
dataType: json
成功: function (msg){
alert(' hurray!Success。' + msg.d); $( this )。nearest(' li')。remove();
},
失败:功能(响应){
alert(response.d);
}
});


});



并制作了一个网络服务方法:



 [WebMethod] 
public string RemoveCategory( string CategoryID)
{
CategoryMasterBAL categorymasterBAL = new CategoryMasterBAL();

return categorymasterBAL.RemoveCategory(CategoryID);
}





但是当我在$ .ajax之前运行这个应用程序时({alert被解雇但没有成功或错误触发,调试控制没有转到C#代码

解决方案

' 。del')。click( function (event){
var parentID = { CategoryID


< blockquote>( this )。nearest(' li').attr(' id')};
parentID = JSON .stringify(parentID);

alert(' 在ajax调用'之前);


.ajax({
type: POST
url: MasterService.asmx / RemoveCategory
data:parentID,
contentType: application / json; charset = utf-8
dataType: json
成功: function (msg){
alert(' hurray!Success。' + msg.d);


on asp.net page i am using the code like this:

$('.del').click(function (event) {
                var parentID = { "CategoryID": $(this).closest('li').attr('id') };
                parentID = JSON.stringify(parentID);

                alert('before ajax calling');
                $.ajax({
                    type: "POST",
                    url: "MasterService.asmx/RemoveCategory",
                    data: parentID,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        alert('hurray! Success. ' + msg.d); $(this).closest('li').remove();
                    },
                    failure: function (response) {
                        alert(response.d);
                    }
                });


            });


and made a web service method as:

[WebMethod]
public string RemoveCategory(string CategoryID)
{
    CategoryMasterBAL categorymasterBAL = new CategoryMasterBAL();

    return categorymasterBAL.RemoveCategory(CategoryID);
}



but when i run this application then before $.ajax({ alert is fired but not fired in success or error and on debugging control not going to C# code

解决方案

('.del').click(function (event) { var parentID = { "CategoryID":


(this).closest('li').attr('id') }; parentID = JSON.stringify(parentID); alert('before ajax calling');


.ajax({ type: "POST", url: "MasterService.asmx/RemoveCategory", data: parentID, contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert('hurray! Success. ' + msg.d);


这篇关于Ajax调用不起作用。任何人都可以帮助我......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆