Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to consume a WCF service in html page using Ajax.
I have published WCF service in local IIS server:
http://localhost:53694/Service1/DownloadAsZip

I tested it by passing a default value in browser and it works fine:

http://localhost:53694/Service1/DownloadAsZip?value=C:\Users\jainp\Desktop\error.txt

Now I wanted to consume this WCF service in html page, the user input will be the file name.
I am trying with following code, but it’s not working. Please guide me to consume this service.
JavaScript
function GetZipFiles() { 
    $.ajax(
    {                
        async: true,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: "http://localhost:53694/Service1/DownloadAsZip",
        dataType: "json",
        data: '{"strFiles":"' + document.getElementById("num1").value + '"}',
       
        success: function (content) {
            DisplayRun(map, content);
        }
    }
    );
}

Thanks in advance
Posted
v3
Comments
CoderPanda 4-Feb-14 4:57am    
Please mention the error you are getting.
Nirav Prabtani 4-Feb-14 4:58am    
Try to find error in inspect element .. :)

In your direct call you are using "value" as querystring parameter.
In your ajax call you are using "strFiles" as parameter.

Is that your intention? Try to use value as parameter in your ajax call and see if it's working then.
If not, consider also adding an event handler to the error function and output the error via alert.

Depending on the jQuery version you are using, please also consider changes in the jQuery API.
See: http://api.jquery.com/jquery.ajax

There are notes that some methods got deprecated so maybe the methods are not the correct names.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900