0

当我在浏览器中键入 URL http://localhost/login/login.aspx 时,我看到我的响应是 {success: true}。当我运行加载我的 html 页面时,我可以从 Fiddler 和调试器中看到调用了 aspx 页面;但是,我的 javascript 没有返回任何内容,它转到 FAILURE 而不是 SUCCESS。

我在其他编程项目中使用过这个 url,但这是我第一次在 Ext JS 中使用它。我在网上看到了各种各样的例子,但似乎没有一个能解决我的问题。以下是我的 javascript 文件,如果我的按钮点击成功返回,我们将不胜感激。

因此,即使 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();
        }
    }
}

default.html 页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>Login Page</title>
  <!-- ExtJS -->
  <script type="text/javascript" src="extjs/ext-all.js"></script>

  <!-- CSS -->
  <link rel="stylesheet" type="text/css" href="css/support-tools.css" />
  <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />

  <script type="text/javascript" src="scripts/login.js"></script>
</head>

<body id="login-page"></body>

</html
4

1 回答 1

0

尝试替换此行:

Response.Write("{success: true}");

使用格式良好的 JSON(属性名称必须全部用 JSON 引号括起来,而不是 javascript):

Response.Write("{\"success\": true}");
于 2013-06-12T17:21:51.270 回答