我在本地环境上创建了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");
}
});
每次调用错误回调都被调用,我无法追踪错误。请帮助我。
答案 0 :(得分: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>