开发者

Json ajax call returning response 200 ok

Here is my code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="<%= ResolveUrl("Scripts/jquery-1.3.2.min.js") %>"></script>
</head>

<body>
    <form id="form1" runat="server">
    <div>
    <input type="button" id="btn" value= "call web service" onclick="callwebservice()" />
    </div>
    </form>
</body>
</html>
<script type="text/javascript" language="javascript">
function Aja开发者_运维问答xFailed(result) {
            alert('call stastus:' + result.status + ' ' + result.statusText);
            alert('responsetest"'+result.responseText);
            alert('errorthrown' + result.errorThrown);

        }
        function callwebservice() {
            $.ajax(
                    {
                        type: "POST",
                        url: "default.aspx/LoginFromFacebook",
                        data: "",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(response) {
                            alert(response);
                        },
                        error: AjaxFailed
                    }
                   );
        }
</script>

code behind -----------------

[WebMethod()]
    public static string LoginFromFacebook()
    {
        return "helloworld";
    }

This is very simple code I have only one web method in my default.aspx file when i am calling the webmethod I am getting response code 200 ok. I investigated using fiddler response is as below HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET Date: Mon, 15 Aug 2011 09:16:21 GMT Content-Length: 1535

don't know why this is happening. I am expecting only string as response where i am getting whole page's html as response.


there is a problem with web site and web applications in visual studio. you can just put the design code in your aspx file or just use web-service instead of the default.aspx.
following link containing basic steps for success ajax request using jQuery, JavaScript or asp.net ajax,

sample site for basic ajax function

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜