0

我正在尝试在 AJAX 调用 POST 中传递一个字符串以检索 JSON 中的列表。

这是我触发呼叫的代码:

<script>

    var a = {};

    a.theatreList = <%= Newtonsoft.Json.JsonConvert.SerializeObject(TheatreList) %> ; 
    $(document).ready(function () {
        $("button").click(function () {
          //  if (a.theatreList != null){                
                //ko.applyBindings(new theatreSel.TheatreModel(a.theatreList));
                ko.applyBindings(new theatreSel.TheatreModel(a.theatreList));
                Regal.showLocationModal();
                return false;

          //  }
        });
      });

</script>

这是包含 .AJAX 调用的 .js

(

function (window) {

    var $ = window.jQuery;
        console = window.console,       
        Regal = window.Regal;
        theatreData = window.theatreData;

        function getEm(zip) {

                $.ajax('/Services/TheatreLocationList.asmx/getTheatres',
                       {
                           data: (zip),
                           type: 'POST',
                           contentType: 'application/json; charset=utf-8',
                           dataType: 'json'
                       }).done(function(){
                           alert("you did it!");
                       });                   

        }

    // declare viewmodel constructors in standard fashion
    function TheatreModel(tl) {
        var self = this;

        getEm("60613");
        self.theatreData = ko.observableArray(tl || []);         

    }



    var theatres = {};
    // declare the module exports     
    theatres.TheatreModel = TheatreModel;

    window.theatreSel = theatres;

最后是 .asmx

namespace Regal.Web.Services
{
    /// <summary>
    /// Summary description for TheatreLocationList
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class TheatreLocationList : System.Web.Services.WebService
    {

        [WebMethod]
        public List<dynamic> getTheatres(String zip)
        {
            List<dynamic> TheatreList = new List<dynamic>();
            int radius = Regal.Core.Helpers.ConfigHelper.GetIntValue("SearchRadius", 30);
            IFrdiTheatreRepository frdiTheatreRepo = FrdiTheatreRepository.CreateBusinessObject();
            TheatreCollection theatreCollection = frdiTheatreRepo.GetAllTheatresFromRegalByPostalCode("60613", radius);
            TheatreList = theatreCollection.ToList<dynamic>();
            return TheatreList;


        } 
    }
}


    })(window)

我收到内部服务器错误 500,但更重要的是,我真的不知道如何制定 AJAX 调用、传递参数和返回 JSON LIST。我一直在尝试找到语法,但我没有看到任何关于我正在尝试做的事情。

Server Error in '/' Application.

Request format is unrecognized for URL unexpectedly ending in '/getTheatres'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/getTheatres'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/getTheatres'.]
   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +713331
   System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +308
   System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +89
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +516
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
4

0 回答 0