Fares Joseph Eid
Fares Joseph Eid

Reputation: 15

How to call function in my dll from jquery

My question is simple, I want to call a function in my dll via jquery.

I'm trying the following

$(window).load(function () {

   $.ajax({
       type: "POST",
       url: "RemotePaymentdll/Class1/CheckPending",
       data: '{}',
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: alert("Success"),
       error: alert("Error")
   })

});

the function in my dll is the following

Public Shared Sub CheckPending()
    Dim aaa = ""

End Sub

I just want to be able to access CheckPending() in my dll from jquery. How can i do it?

Upvotes: 0

Views: 1901

Answers (3)

trucker_jim
trucker_jim

Reputation: 572

I'd suggest using an HttpHandler to do the server side work, you can call it via javascript:

You could create an .ashx file with some code a bit like this:

<%@ WebHandler Language="VB" Class="MyTestHandler" %>
Imports System
Imports System.Web
Imports System.IO
Imports System.Data.SqlClient
Imports System.Data
Imports System.Xml

    Public Class MyTestHandler : Implements IHttpHandler


        Private ReadOnly Property Parameter1() As Integer
            Get
                If Not IsNothing(HttpContext.Current.Request.QueryString("Parameter1")) Then
                    Return CInt(HttpContext.Current.Request.QueryString("Parameter1"))
                Else
                    Return -1
                End If
            End Get
        End Property

        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
            context.Response.Clear()
            context.Response.Buffer = True
            context.Response.Expires = -1
            context.Response.Write("YOUR OUTPUT HERE")
            context.Response.Flush()
            context.Response.End()
        End Sub

        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property

    End Class

Upvotes: 0

Sven Sch&#252;rmann
Sven Sch&#252;rmann

Reputation: 612

You can try something like this:

$(window).load(function () {
   var ObjFromDll = new ActiveXObject("RemotePaymentdll.Class1"),
       result = ObjFromDll.CheckPending();
});

This will only works in IE...

If you have problems to instantiate the ActiveXObject have look here

Upvotes: 0

Pu Wang
Pu Wang

Reputation: 101

Normally, JS can only access local resources plus URL resources.

I suggest that create a Resuful API at server side to call the CheckPending method. and JQuery consumes this API.

Upvotes: 1

Related Questions