jQuery Ajax:仅执行Page_Load方法,而不执行预期的方法 [英] Jquery Ajax: Only Page_Load method is being executed, not the intended one
问题描述
我应该返回一个csv文件,所以我添加了将从客户端调用的此方法.目前,此方法返回一个简单的字符串.
I'm supposed to return a csv file, so I added this method that I will be calling from the client side. For now, this method is returning a simple string.
public partial class ResourceEdit_PriceSheet : xCI.Site.Web.BasePage
{
protected void Page_Load( object sender, EventArgs e )
{
}
[WebMethod]
public string GenerateVendorPriceSheet(int suppID)
{
return "Succes!!!";
}
}
这是ajax
function exportVendorPriceSheet() {
var suppID = getParameterByName('SuppID');
var url = '/ResourceEdit/ResourceEdit_PriceSheet.aspx/GenerateVendorPriceSheet';
var id = { "suppID": suppID };
$.ajax({
type: "POST",
url: url,
data: id,
dataType: "application/json",
cache: false,
success: function (result) {
alert(result)
}
});
};
当我运行该应用程序时,没有任何反应.在执行Page_Load
旁边的那个时,未击中该断点.并且响应包含整个页面,而不是成功!!!".
When I run the application, nothing is happening. The break point is not being hit GenerateVendorPriceSheet
while the one next to Page_Load
is being executed. And the response contains the whole page instead of "Success!!!".
但是,我读过的所有文章都说这是如何从apx页面调用方法的方法.我想念什么吗?
Yet, all the posts I've read says that's how to call a method from a aspx page. Am I missing something?
感谢您的帮助.
===================
====================
这里有一些标题
Request URL:http://localhost/ResourceEdit/ResourceEdit_PriceSheet.aspx/GenerateVendorPriceSheet
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:11
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Form Data
suppID=2974
推荐答案
基于标头检查(Chrome开发工具):
Based on the header inspection (Chrome dev tools):
- 您正在发送
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
所以(contentType
):
$.ajax({
type: 'POST',
url: url,
data: id,
contentType: 'application/json; charset=utf-8',
dataType: 'json'
Hth ....
这篇关于jQuery Ajax:仅执行Page_Load方法,而不执行预期的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!