jQuery Ajax呼叫在即工作,但不能工作谷歌浏览器,Firefox,苹果浏览器 [英] jquery ajax call is working in ie but not working google chrome,firefox,safari

查看:91
本文介绍了jQuery Ajax呼叫在即工作,但不能工作谷歌浏览器,Firefox,苹果浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我一直在努力解决一个问题.
使用jquery进行Web服务的ajax调用可以在IE中正常运行,但不能在googlechrome,firefox,safari中运行.

在googlechrome,safari和firefox中,其响应为未定义

这是我的代码.

在aspx页面中

Hello,

i have struggled with one problem.
ajax call with jquery for webservice working fine in ie but not working in googlechrome, firefox,safari.

in googlechrome,safari and firefox it gives response as undefined

this is my code..

in aspx page

$.ajax({
                type: "POST",
                url: "xxx.svc/logindetails",
                contentType: "application/json",
                data: '{ "UserName": "' + UserName + '","Password": "' + Password + '"}',
                async: false,
                success: function (data) {
                    if (data.text == '') {
                       // xxxxxxxxx  
                    }
                    else{//redirect}
},
                error: function (data) {
                    //alert();
                }
            });



在xxx.svc中:




in xxx.svc:


OperationContract]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.WrappedRequest,
            ResponseFormat = WebMessageFormat.Xml
        )]
public string GetUserDetailsbyLogIn(string UserName, string Password)
        {
string msg="";
// checking user exist or not
           return msg;
}


任何人都可以知道的这个请帮助我
在此先感谢...


anyone can know about this pls help me
thanks in advance...

推荐答案

.ajax({ 类型:" , 网址:" , contentType:" , 数据:' {"UserName":' + UserName + ' ,"密码:"' +密码+ ' }', 异步:错误, 成功:功能(数据){ 如果(data.text == ' '){ // xxxxxxxxx } 其他 {// 重定向} }, 错误:功能(数据){ // alert(); } });
.ajax({ type: "POST", url: "xxx.svc/logindetails", contentType: "application/json", data: '{ "UserName": "' + UserName + '","Password": "' + Password + '"}', async: false, success: function (data) { if (data.text == '') { // xxxxxxxxx } else{//redirect} }, error: function (data) { //alert(); } });



在xxx.svc中:




in xxx.svc:


OperationContract]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.WrappedRequest,
            ResponseFormat = WebMessageFormat.Xml
        )]
public string GetUserDetailsbyLogIn(string UserName, string Password)
        {
string msg="";
// checking user exist or not
           return msg;
}


任何人都可以知道的这个请帮助我
在此先感谢...


anyone can know about this pls help me
thanks in advance...


我认为问题在于接受Content-Type HTTP标头.
请在此处查看我编辑过的答案,然后尝试一下是否可行.
I think problem lies in Accepts an Content-Type HTTP headers.
Please see my edited answer here, and try if this will work.
http://stackoverflow.com/questions/13246023/unable-to-parse-the-json-returned-by-the-server-youre-trying-to-decode-an-inva/13246219#13246219[^]


这篇关于jQuery Ajax呼叫在即工作,但不能工作谷歌浏览器,Firefox,苹果浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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