Is it possible to show a PopUp from a web service

丶灬走出姿态 提交于 2019-12-11 01:39:28

问题


Asp.Net 4.0

In my web applicaion i'm using web service methods. Is it possible to show a popup to request information from a user from a method in the web service?


回答1:


Without further details about the web service you are invoking, I will give you a quite general example. It requires jQuery.

It assumes that the web service is invoked by some trigger in the client: it could be a user event (click, key press) or a DOM event (load, ready). A handler is assigned to this event. In the case of a button-click event then:

$('#btnCallService').bind('click'
    , {dataObject: 'add evet related data here'}
    , function(event){
        /* here a handler is executed when btnCallService is clicked  */
        callServiceHandler(event.data)
    }
);

Here is the body of the handler, with the call to the service.

function callServiceHandler(eventData) {
    $.ajax({
        type: "GET",
        url: "url_to_your_service_method",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: yourWebMethodArguments,
        success: function (resultData) {
            /* everything is right! result data are available for client side processing and rendering */

            alert('Request completed!');
        }
        error: function (req, status, message) {
            /* something is wrong: guide the user */
            alert('Unable to execute your request: \n' + message);
        },

    });
}

As you can see, the web method calls no popup at all. You could centralize the handler in a library, and call it from every where in your site.




回答2:


Yes you can use jQuery to call a function of web-service and you can show any popup




回答3:


you can call web methods using jquery, and based on the received data you can show msg box. refer to this for better idea



来源:https://stackoverflow.com/questions/15505715/is-it-possible-to-show-a-popup-from-a-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!