简体   繁体   English

从javascript文件调用javascript函数(在ASPX中)页面

[英]Call a javascript function (in ASPX) page from a javascript file

I have a javascript file (viewer.js) situated in Scripts/viewer.js My default.aspx has a javascript functions that calls ac# function in the default.aspx.cs ( it sends a http webrequest) 我在Scripts / viewer.js中有一个javascript文件(viewer.js)我的default.aspx有一个javascript函数,它在default.aspx.cs中调用ac#函数(它发送一个http webrequest)

Now I want to call from the viewer.js the function in default.aspx which calls the c# function. 现在,我想从viewer.js调用default.aspx中的函数,该函数调用c#函数。

How can I handle this in my viewer.js? 如何在viewer.js中处理此问题?

I need to do this because I work with 3D objects and the select event is on the viewer.js 我需要这样做,因为我使用3D对象并且select事件在viewer.js上

When I select the 3D object it needs to call the function in default.aspx... 当我选择3D对象时,它需要在default.aspx中调用该函数。

Scripts/viewer.js 脚本/viewer.js

function ClickPickItem(item) {

        $("#properties").show();
        /*Call function App() */
    }

Default.aspx Default.aspx

function App() {
     PageMethods.Connect(callback);
 }

Default.aspx.cs Default.aspx.cs

     [WebMethod]
        public static string Connect()
        {
            string rsp = DigestAuthFixer.GrabResponse("http://<username>:<password>@nextbus.mxdata.co.uk/nextbuses/1.0/1");
... CODE TO MAKE HTTPWEBREQUEST

}

Sorry if I'm not clear enough 对不起,如果我不清楚

I don't see another option like this 我看不到这样的其他选择

What I need to do? 我需要做什么?

Thanks! 谢谢!

Assuming viewer.js is included in the Default.aspx 's html, after the declaration of App : 假设App声明之后, viewer.js包含在Default.aspx的html中:

<script type="text/javascript" src="Scripts/viewer.js"></script>

You should simply be able to invoke the function, assuming it was created within global scope (or the scope of the document). 假设该函数是在全局范围(或​​文档范围)内创建的,则您应该能够简单地调用该函数。

function ClickPickItem(item) {

    $("#properties").show();
    App();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM