Wcf并在我的mvc 3 Razor应用程序中使用Ajax jquery获取其服务 [英] Wcf and get its services using Ajax jquery in my mvc 3 Razor Application

查看:72
本文介绍了Wcf并在我的mvc 3 Razor应用程序中使用Ajax jquery获取其服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我正在尝试使用Ajax访问My Wcf服务它没有获得结果并给出400,405和其他错误但是当我使用Controller方法时它会给出所有值。

亲切地给我解决我的问题。





问题: -

我想在My MVC3应用程序中使用Ajax Post方法使用Wcf服务方法。

i使用: -



var url1 =''http:/ /localhost:50404/Service1.svc/GetData'';



$ .ajax({

url:url1,

类型:POST,

dataType:json,

contentType:application / json; charset = utf-8,

//数据:JSON.stringify({value:1}),

//或者在没有Json的情况下也使用

成功:函数(数据) {

var res = data.d.toStri ng();

alert();

alert(res);



}



错误:function(xhr,ajaxOptions,thrownError){

alert(''Error''+ xhr.statusText + xhr.responseText);

//它跳到这里

}



});







和USed这在我的控制器中

ServiceReference1.Service1Client clientObj = new ServiceReference1.Service1Client();

ViewBag.name = clientObj.GetData(rizwan);

它给出了所有价值

ViewBag.name









所以请帮帮我......

解决方案

.ajax({

url:url1,

类型:POST,

dataType:json,

contentType:application / json; charset = utf-8,

//数据:JSON.stringify( {值:1}),

//或者在没有Json的情况下使用

成功:函数(数据){

var res = data .d.toString();

alert();

alert (res);



}



错误:function(xhr,ajaxOptions,thrownError){

alert(''错误''+ xhr.statusText + xhr.responseText);

//它跳到这里

}



});







和USed这在我的控制器中

ServiceReference1.Service1Client clientObj = new ServiceReference1.Service1Client();

ViewBag.name = clientObj.GetData(rizwan);

它给出了所有价值

ViewBag.name









所以请帮帮我......

Hello
I am trying to get Access of My Wcf Service using Ajax it not Get result and give 400,405 and other error but when i used by Controller method it give all values.
So kindly give me Solution of my problem.


Problem :--
I Want to used Wcf Service Method using Ajax Post method in My MVC3 Application.
i used :-

var url1 = ''http://localhost:50404/Service1.svc/GetData'';

$.ajax({
url: url1,
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
// data: JSON.stringify("{value:1}"),
//or Also Used Without Json
success: function (data) {
var res = data.d.toString();
alert();
alert(res);

}
,
error: function (xhr, ajaxOptions, thrownError) {
alert(''Error '' + xhr.statusText + xhr.responseText);
//it jump Here
}

});



and USed This in my controller
ServiceReference1.Service1Client clientObj = new ServiceReference1.Service1Client();
ViewBag.name = clientObj.GetData("rizwan");
it gives all value in
ViewBag.name




So please help me...

解决方案

.ajax({
url: url1,
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
// data: JSON.stringify("{value:1}"),
//or Also Used Without Json
success: function (data) {
var res = data.d.toString();
alert();
alert(res);

}
,
error: function (xhr, ajaxOptions, thrownError) {
alert(''Error '' + xhr.statusText + xhr.responseText);
//it jump Here
}

});



and USed This in my controller
ServiceReference1.Service1Client clientObj = new ServiceReference1.Service1Client();
ViewBag.name = clientObj.GetData("rizwan");
it gives all value in
ViewBag.name




So please help me...


这篇关于Wcf并在我的mvc 3 Razor应用程序中使用Ajax jquery获取其服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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