PHP Web服务无法从jQuery AJAX运行 [英] PHP web service not working from jQuery AJAX

查看:67
本文介绍了PHP Web服务无法从jQuery AJAX运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在社交环境中创建了Restful Web服务. 在本地计算机上. 当我使用REST控制台对其进行测试时,它会返回响应.

I have created Restful web service in jomsocial environment. It's on the local machine. When I test it using REST console it return's response.

形成的本地网址是...

local url formed is...

http://localhost:5454/kisan-06/index.php?option=com_api&format=raw&app=users&resource=login&key=dfd8a84f8cdce807ae1d30a838415ea37eaa075c

问题:

当我使用jQuery.ajax进行调用时,总是会调用错误回调函数.

When I call same using jQuery.ajax, always error callback function is getting called.

Ajax通话是...

Ajax call is...

$.ajax({
    type: "POST",
    url: "http://localhost:5454/kisan-06/index.php?option=com_api&format=raw&app=users&resource=login&key=dfd8a84f8cdce807ae1d30a838415ea37eaa075c",
    data: "{ username: 'sai.kiks2@gmail.com', password: '123456'}",
    contentType: "application/json; charset=utf-8",
    cache : false,
    dataType: "json",
    success: function(data) {
        alert("in success");
    },
    error: function(jqXHR,error, errorThrown){
        //alert("There was an error loggin in");
        alert("responseXML ",jqXHR.responseXML);
        alert("responseText: ",jqXHR.responseText);
        alert("errorThrown: ",errorThrown);
    }
});

我有一个asp.net Web服务,返回的响应为...

I have a asp.net web service, which was returning response as...

<?xml version="1.0" encoding="utf-8"?>
<string>{"UserID":"180339206","LogInName":"Amol Chakane","IsValid":"True","UserRoleID":"1","IsPending":"0","IsOrganization":"False"}</string>

jomsocial网络服务的响应是...

Response from jomsocial web service is...

["UserID : 475", "LogInName : kruti patil", "IsValid : True", "UserRoleID : 1", "IsPending : 0", "IsOrganization : False"]

我搜索了此问题,但找不到解决方案. 请帮助我.

I searched for this issue, but couldn't find solution. Please help me in this.

编辑#1

试图获取其他格式的响应.

Tried to get response in other format.

{
"UserID": "475",
"LogInName": "kruti patil",
"IsValid": "Yes",
"UserRoleID": "1",
"IsPending": "NO",
"IsOrganization": "No",

}

仍然不起作用:(

谢谢

推荐答案

经过大量搜索,终于找到了解决此问题的方法. :)

After lot of search finally I found solution to this issue. :)

代替 localhost 需要使用 10.0.2.2 这个网络地址 COZ Android模拟器无法识别本地主机 请参考

Instead of localhost need to use 10.0.2.2 this network address coz android emulator doesn't recognize localhost refer this

现在至少调用了成功回调

Now at least success callback is called

ajax呼叫是..

ajax call is..

$.ajax({
    type: "POST",
    url: "http://10.0.2.2:5454/kisan-06/index.php?option=com_api&format=raw&app=users&resource=login&key=dfd8a84f8cdce807ae1d30a838415ea37eaa075c",
    data: {username: 'sai.kiks2@gmail.com', password: '123456'},
    success: function(data, textStatus, jqXHR) {
        alert("in success");
    },
        error: function(jqXHR, textStatus, errorThrown){
            alert("There was an error loggin in");
        }
});

但是现在我面临另一个问题...

But now I am facing another problem...

如何访问成功回调中返回的数据?

How to access data returned in success callback?

这篇关于PHP Web服务无法从jQuery AJAX运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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