ASP页面中的Ajax返回500 [英] Ajax in asp page return 500

查看:69
本文介绍了ASP页面中的Ajax返回500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行ajax POST,但始终返回500服务器错误.

I'm trying to execute an ajax POST, but always return an 500 Server Error.

对于测试,我简化了请求.

For perfom a test, I simplify the request.

JavaScript代码:

Javascript code:

 $(document).ready(function() {
  // Add the page method call as an onclick handler for the div.
      $("#prova").click(function() {
        $.ajax({
          type: "POST",
          url: "Solicitud.aspx/GetDate",
          data: {someParameter: "some value"},
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(msg) {
            // Replace the div's content with the page method's return.
            console.log("Resposta"+ msg.d);
          }
        });
      });
        });

班级代码

namespace picovirgiliop
{
    public partial class Solicitud : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        public static string GetDate(string someParameter)
        {
            return DateTime.Now.ToString();
        }
...

编辑

POST http://localhost:63010/Solicitud.aspx/GetDate 500(内部服务器错误)

POST http://localhost:63010/Solicitud.aspx/GetDate 500 (Internal Server Error)

  • 发送@ jquery-3.3.1.js:9600
  • ajax @ jquery-3.3.1.js:9206
  • (匿名)@ Solicitud:300
  • 调度@ jquery-3.3.1.js:5183
  • elemData.handle @ jquery-3.3.1.js:4991

推荐答案

根据您的代码回顾,我可以在行上看到问题

As per your code review, I can see problem at line

数据:{someParameter:某些值"},

data: {someParameter: "some value"},

应该是下面的样子,

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

OR

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

这篇关于ASP页面中的Ajax返回500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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