使用Ajax在html页面中使用WCF服务 [英] consume a WCF service in html page using Ajax

查看:83
本文介绍了使用Ajax在html页面中使用WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Ajax在html页面中使用WCF服务。

我在本地IIS服务器上发布了WCF服务:

http :// localhost:53694 / Service1 / DownloadAsZip



我通过在浏览器中传递默认值来测试它并且它工作正常:



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



现在我想在html页面中使用这个WCF服务,用户输入将是文件名。

我正在尝试使用以下代码,但它无法正常工作。请指导我使用此服务。

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.

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

推荐答案

.ajax(
{
async: true
类型: 获取
contentType: application / json; charset = utf-8
url: http:// localhost:53694 / Service1 / DownloadAsZip
dataType: json
data: {strFiles:' + document .getElementById ( num1)。value + ' }'

成功: function (content){
DisplayRun(map,content);
}
}
);
}
.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


在您的直接电话中,您使用value作为查询字符串参数。 />
在你的ajax调用中,你使用strFiles作为参数。



这是你的意图吗?尝试在ajax调用中使用value作为参数,然后查看它是否正常工作。

如果没有,请考虑向错误函数添加事件处理程序并通过警报输出错误。



根据您使用的jQuery版本,请同时考虑jQuery API中的更改。

请参阅:http://api.jquery.com/jquery.ajax



有些说明有些方法已被弃用所以这些方法可能不是正确的名称。
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.


尝试使用使用Jquery / JavaScript调用跨域WCF服务 [ ^ ]。


这篇关于使用Ajax在html页面中使用WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆