javascript - 从 Ext JS 4.2 调用 aspx 时遇到问题

标签 javascript asp.net .net css extjs

我正在尝试调用 ASPX url;然而,返回一直以失败告终。

我在其他编程元素中使用过这个 url,但这是我第一次在 Ext JS 中使用它。我在网上看到了各种例子,但似乎没有一个能解决我的问题。以下是我的 javascript 文件,如有任何帮助,我将不胜感激,希望能在我点击按钮时获得成功返回。

我用过 Fiddler,它正在调用 url;然而,即使返回的 JSON 是 {success: true},它也没有命中我的 Debugger.Launch() 语句或调用我的“成功”警报。

因此,即使 fiddler 显示正在对 http://localhost/login/login.aspx 进行调用,它也没有从 javascript 调用输入我的 C# 代码。

Ext.require([
    'Ext.form.*',
    'Ext.window.Window'
]);

Ext.onReady(function () {

    Ext.QuickTips.init();

    var field = new Ext.form.field.Text({
        renderTo: document.body
    }),
        fieldHeight = field.getHeight(),
        padding = 5,
        remainingHeight;

    field.destroy();

    remainingHeight = padding + fieldHeight * 2;

    var login = new Ext.form.Panel({
        border: false,
        fieldDefaults: {
            msgTarget: 'side',
            labelWidth: 100
        },
        defaultType: 'textfield',
        bodyPadding: padding,

        items: [{
            xtype: 'box',
            region: 'west',
            width: 128,
            height: 46,
            autoEl: { tag: 'img', src: 'images/logo.png' },
            style: 'margin: 10px 0px 15px 15px'
        }, {
            allowBlank: false,
            fieldLabel: 'Company Name',
            name: 'company',
            emptyText: 'Company ID',
            style: 'margin: 10px 0px 10px 30px'
        }, {
            allowBlank: false,
            fieldLabel: 'User ID',
            name: 'user',
            emptyText: 'User Name',
            style: 'margin: 10px 0px 10px 30px'
        }, {
            allowBlank: false,
            fieldLabel: 'Password',
            name: 'pass',
            emptyText: 'Password',
            inputType: 'password',
            style: 'margin: 10px 0px 10px 30px'
        }]
    });

    new Ext.window.Window({
        autoShow: true,
        title: 'Support Tools Login',
        resizable: false,
        closable: false,
        width: 350,
        height: 250,
        layout: 'fit',
        plain: true,
        items: login,
        constrain: true,
        draggable: false,

        buttons: [{
            text: 'Login',
            formBind: true,

            handler: function () {
                login.getForm().submit({
                    method: 'POST',
                    url: 'http://localhost/login/login.aspx',
                    waitTitle: 'Connectiong',
                    waitMsg: 'Sending data...',

                    success: function (login, action) {
                        Ext.Msg.alert('Success');
                    },

                    failure: function (login, action) {
                        Ext.Msg.alert('Failure')
                    }
                });
            }
        }]
    });
});

Aspx文件:

using System;
using System.Diagnostics;
using System.Web;
using SupportToolsCommon;

namespace App.login
{
    public partial class login : System.Web.UI.Page
    {
        private static Database db;

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Write("{success: true}");
            Response.End();
        }
    }
}

最佳答案

您的代码是正确的。我在这个 jfFiddle 中测试过,只需更改网址,一切正常。请求正在触发,响应已收到...

url: '/echo/json/',
params: {json: Ext.encode({success: true}), delay: .5},

所以您的 URL 或服务器有问题。正如我在评论中所说,您确定要使用 https://localhost/... 而不是简单地 http://localhost/...?

关于javascript - 从 Ext JS 4.2 调用 aspx 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17064126/

相关文章:

c# - 我可以不使用 try catch() 来忽略错误吗?

javascript - HTML 5 Canvas 似乎重绘移除的部分

javascript - HTML/JS 中的弹出窗口只需点击两次即可弹出

javascript - 在 gridview 中(标签在点击时变成文本框)一次一个

asp.net - F# 命名空间或模块 'XXXX' 未定义

asp.net - 我们可以从 azure 检索 asp.net 项目吗?

.net - 默认情况下,线程是否在多个内核上运行?

.net - 最佳 JIT 优化

javascript - 异步/等待预期行为

javascript - 将异步方法之一重写为使用 Promise 的方法