Json Ajax调用返回响应200 ok [英] Json ajax call returning response 200 ok
问题描述
这是我的代码
<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 AjaxFailed(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";
}
这是非常简单的代码,当我调用webmethod时,我的default.aspx文件中只有一个Web方法,我得到的响应代码为200 ok.我调查了提琴手响应如下HTTP/1.1 200 OK缓存控制:私有内容类型:text/html;字符集= utf-8伺服器:Microsoft-IIS/7.5X-AspNet版本:2.0.50727X-Powered-by:ASP.NET日期:2011年8月15日星期一09:16:21 GMT内容长度:1535
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
不知道为什么会这样.我期望只有字符串作为响应,而我将整个页面的html作为响应.
don't know why this is happening. I am expecting only string as response where i am getting whole page's html as response.
推荐答案
Visual Studio中的网站和Web应用程序存在问题.您可以只将设计代码放在aspx文件中,或者只使用Web服务而不是default.aspx.
以下链接包含使用jQuery,JavaScript或asp.net ajax成功进行ajax请求的基本步骤,
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,
这篇关于Json Ajax调用返回响应200 ok的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!