Results 1 to 3 of 3

Thread: Ajax URL Problem

  1. #1
    Ext JS Premium Member
    Join Date
    Feb 2009
    Posts
    102
    Answers
    5
    Vote Rating
    1
      0  

    Default Answered: Ajax URL Problem

    I am having a problem with the sample 'Ext JS Application and Web API' application generated by the latest Visual Studio Plugin, ExtJS 6.5.1 and cmd 6.5.1.240. When I make an Ajax call to an API Controller, the program is looking for the the controller in the localhost:nnnnn/Sencha/Api directory. I expected it to look in the localhost:nnnnn/Api directory.

    Here is the code I have inserted into the launch function of Application.js:

    Code:
    Ext.define('ExtApplication.Application', {
        extend: 'Ext.app.Application',
    
    
        name: 'ExtApplication',
    
    
        quickTips: false,
        platformConfig: {
            desktop: {
                quickTips: true
            }
        },
    
    
        launch: function () {
            Ext.Ajax.request({
                url: 'Api/AccountManager/GetAccountManagerInfo',
                scope: this,
                callback: this.onAfterAjaxReq
            });
        },
    
    
        onAfterAjaxReq: function (options, success, result) {
        },
    
    
        onAppUpdate: function () {
            Ext.Msg.confirm('Application Update', 'This application has an update, reload?',
                function (choice) {
                    if (choice === 'yes') {
                        window.location.reload();
                    }
                }
            );
        }
    });
    Attached is the result of running the application showing that it is expecting to find the controller in the Sencha/Api directory rather than the Api directory. What am I doing wrong?
    Attached Images Attached Images

  2. I submitted a ticket and got this response that fixed the problem:

    The simplest way for you is to change default controller routing. You can do it in WebApiConfig.cs file:
    Code:
    
    
    Code:
    using System;using System.Collections.Generic;
    using System.Linq;
    using System.Web.Http;
    
    namespace MyApp
    {
        public static class WebApiConfig
        {
            public static void Register(HttpConfiguration config)
            {
                // Web API configuration and services
    
                // Web API routes
                config.MapHttpAttributeRoutes();
    
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "sencha/api/{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );
            }
        }
    }
    It's needed to change routeTemplate parameter to "sencha/api/{controller}/{id}" and then your example should work.

  3. #2
    Ext JS Premium Member
    Join Date
    Feb 2009
    Posts
    102
    Answers
    5
    Vote Rating
    1
      0  

    Default

    I think the problem is not with the application generated by the Visual Studio Plugin but with the way that I am using the application. Below is my api controller program that I saved in AccountManagerController.cs in the Api directory.

    Code:
    using System.Web.Http;
    
    
    namespace ExtApplication.Controllers
        {
        public class AccountManagerController : ApiController
            {
            public IHttpActionResult GetAccountManagerInfo()
                {
                return Ok(new { data = "ABC", success = true });
                }
            }
        }
    As shown in the previous entry, I am attempting to call this controller with the following ajax call:

    Code:
            Ext.Ajax.request({
                url: 'Api/AccountManager/GetAccountManagerInfo',
                scope: this,
                callback: this.onAfterAjaxReq
            });
        },
    What should the ajax call and the corresponding controller program look like to use the application structure of the generated application?

  4. #3
    Ext JS Premium Member
    Join Date
    Feb 2009
    Posts
    102
    Answers
    5
    Vote Rating
    1
      0  

    Default

    I submitted a ticket and got this response that fixed the problem:

    The simplest way for you is to change default controller routing. You can do it in WebApiConfig.cs file:
    Code:
    
    
    Code:
    using System;using System.Collections.Generic;
    using System.Linq;
    using System.Web.Http;
    
    namespace MyApp
    {
        public static class WebApiConfig
        {
            public static void Register(HttpConfiguration config)
            {
                // Web API configuration and services
    
                // Web API routes
                config.MapHttpAttributeRoutes();
    
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "sencha/api/{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );
            }
        }
    }
    It's needed to change routeTemplate parameter to "sencha/api/{controller}/{id}" and then your example should work.

Similar Threads

  1. Ajax problem
    By crisedward in forum Sencha Touch 1.x: Discussion
    Replies: 6
    Last Post: 8 Aug 2011, 2:21 PM
  2. Ext.Ajax Problem
    By ashadi.cahyadi in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 6 Aug 2011, 8:24 PM
  3. Problem of Ajax with CGI
    By tlili in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 12 Jun 2009, 7:57 AM
  4. problem with ajax
    By srmo642002 in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 7 Nov 2007, 9:36 AM
  5. Problem in send ajax request :The Ext.Ajax is null or not Object
    By flyingpig in forum Ext 1.x: Help & Discussion
    Replies: 7
    Last Post: 27 Aug 2007, 11:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •