2

可能重复:
PHP Web 服务无法从 jQuery AJAX 工作

我在本地环境
url 上创建了 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: 'sai.kiks2@gmail.com', 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");
    }
});

每次调用错误回调,我都无法跟踪错误。请帮助我。

4

1 回答 1

0

我认为您需要在 URL 中指定需要在 ajax 调用时调用的特定方法。我还没有开发 php web 服务,但是在 Asp 中我们调用如下。

 <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>
于 2012-08-23T10:24:06.157 回答