我可以发送Ajax请求.aspx页面中,甚至是否有可能写JSON? [英] Can i send ajax request to .aspx page, even Is it possible to write JSON?

查看:144
本文介绍了我可以发送Ajax请求.aspx页面中,甚至是否有可能写JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送Ajax请求的.asmx页或asp.net web方法一般是用,但我想知道,我可以发送Ajax请求为.aspx以及如何处理响应的结果。结果
与Web方法.ASMX页面句柄的要求,是否有可能与.aspx页面中?

Sending ajax request to .asmx page or web method in asp.net is used generally but i want to know, can i send ajax request to .aspx and how to handle responsive result.
.ASMX page handle request with web method, is it possible with .ASPX page?

推荐答案

您可以定义code Web方法的aspx页面的背后,然后给他们打电话。

you can define web methods in code behind of your aspx page and then call them.

[WebMethod]
public static string doSomething(int id)
{
    ....
    return "hello";
 }

和在你的jQuery code

and in your jQuery code

$.ajax({
    type: "POST",
    url: "YourPage.aspx/doSomething",
    data: "{'id':'1'}",
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function (data) {
        var returnedstring = data.d;
        var jsondata = $.parseJSON(data.d);//if you want your data in json
    }
});

这里是开始一个很好的链接

Here is a good link to get started

这篇关于我可以发送Ajax请求.aspx页面中,甚至是否有可能写JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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