简体   繁体   中英

How to consume a WCF Service using jquery?

I've a Wcf Service Application with jsonp that I consume using jquery like this:

    function CallService() {
        $.ajax({
            type: Type, //GET or POST or PUT or DELETE verb
            url: Url, // Location of the service
            data: Data, //Data sent to server
            contentType: ContentType, // content type sent to server
            dataType: DataType, //Expected data format from server
            processdata: ProcessData, //True or False
            success: function (msg) {//On Successfull service call
                ServiceSucceeded(msg);
            },
            error: ServiceFailed// When Service call fails
        });
    }

I've hosted the WCF Service using IIS 5.1 and now I want to use the Windows Authentication parameter.

What do I've to do in jquery for this to work?

I guess you need to implement www-authentication for your service:

Adding basic HTTP auth to a WCF REST service

then, according to the jQuery documentation, you can make authenticated ajax calls by setting the username and password variables accordingly:

http://api.jquery.com/jQuery.ajax/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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