开发者

how to handle string return with jquery post

I'm calling a webservice that returns a string, but I cannot figure a way how to handle the return string. This is the code that I'm using now:

$('#soap-form').submit(function () {
            $.post($(this).attr('action'), { Source: "values here are", SiteGroup: $('#dropdown-select').val(), Identifier: $('#indentifier-input').val(), Password: $('#password-input').val() }, function (data) { if (data != null) alert(data); });
            return false;
        });

It returns just an empty string, but the method is setup to return error messages and success etc.. any ideas?

EDIT

firebug:

response tab is empy, but when I don't use t开发者_如何学Pythonhe jquery post the method returns a <string>error</string>

EDIT

Do I have to do anything for the method to return string? Like enter a return type or is it enough with string as type for the method?


$('#soap-form').submit(function () {
            $.post(
                    $(this).attr('action'), 
                    { Source: "values here are", SiteGroup: $('#dropdown-select').val(), Identifier: $('#indentifier-input').val(), Password: $('#password-input').val() }, 
                    function (data) { 
                          if (data != null) alert(data); 
                    }
             );
            return false;
 });

this is better

to catch an error, you can use .error();

$('#soap-form').submit(function () {
            $.post(
                    $(this).attr('action'), 
                    { Source: "values here are", SiteGroup: $('#dropdown-select').val(), Identifier: $('#indentifier-input').val(), Password: $('#password-input').val() }, 
                    function (data) { 
                          if (data != null) alert(data); 
                    }
             ).error(function(){
                 // do whatever you want with this error
             });
            return false;
 });

demo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜