2012-08-23 86 views
2

Possible Duplicate:
PHP web service not working from jQuery AJAX如何使用jQuery ajax調用RESTful php web服務?

我已經在本地創建envirnoment PHP Web服務
網址是:

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

我在我的Android應用程序的PhoneGap調用此使用jQuery.ajax。

Ajax調用是:

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

每次錯誤回調獲取的叫,我不能跟蹤誤差。請幫助我。

+1

更換你'錯誤。告訴我們這些是什麼。另外,在瀏覽器中按F12,運行你的AJAX查詢,然後進入網絡選項卡,並告訴我們在那裏發生了什麼錯誤。 – Scotty

+0

@Scotty實現的變化... ** textStatus ** =錯誤和** errorThrown ** =空 在瀏覽器獲取**加載取消**爲index.php –

回答

0

我認爲你需要在需要在ajax調用上調用的URL中指定一個特定的方法。我還沒有開發PHP的Web服務,但在Asp中我們打電話如下。用`誤差函數()`:功能(jqXHR,textStatus,errorThrown)`和`警報()`的** textStatus **和** ** errorThrown值

<script type="text/javascript"> 

    $(document).ready(function() { 
    $("#MainContent_ButtonSearch").click(function() { 
    /// hide employee details (if shown) 
    $("#empDetails").hide("slow"); 
    var empId = $("#MainContent_TextBoxEmpId").val(); 
    $.ajax({ 
     type: "POST", 
     dataType: "json", 
     contentType: "application/json", 
     **url: "EmployeeService.asmx/GetEmployeeById",** 
     data: "{'employeeId': '" + empId.toString() + "'}", 
     success: function (data) { 
     $("#textId").html(data.d.ID); 
     $("#textName").html(data.d.FullName); 
     $("#textTitle").html(data.d.Title); 
     $("#textDepartment").html(data.d.Department); 
     /// show employee details 
     $("#empDetails").show("slow"); 
    }, 
    error: function() { 
    alert("Error calling the web service."); 
    } 
    }); 
    }); 
    }); 

    </script> 
+0

我有更早的asp.net web服務。這工作正常。但是現在我有php web服務。哪個有問題。 –