weixin_33670713 2015-05-20 20:43 采纳率: 0%
浏览 48

使用数据进行AJAX发布

This is in my default.aspx

        $.ajax({
            url: "Default.aspx/Myfunction",
            dataType: "json",
            type: "POST",
            data: {someParameter: "some value"},
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                alert(data.d);
            },
            error: function (d) {
                alert("error");
            }
        });

And this is in my codebehind:

    [WebMethod]
    public static string Myfunction(string someParameter)
    {
        return "hello";
    }

It keeps going to the error. I see that if I send the Ajax request with null for data and no parameters on the function I get the data "hello" out. So there is some issue in how I send the data, but it is unclear what

  • 写回答

4条回答 默认 最新

  • weixin_33716557 2015-05-20 20:47
    关注

    Change this line:

    data: {someParameter: "some value"},
    

    to:

    data: {"someParameter": "some value"},
    

    JSON object properties needs to be enclosed with quotes.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效