Javascript Phonegap无法进行ajax调用
我正在调用一个javascript函数,该函数在单击按钮时进行ajax调用,代码为:Javascript Phonegap无法进行ajax调用,javascript,ajax,cordova,Javascript,Ajax,Cordova,我正在调用一个javascript函数,该函数在单击按钮时进行ajax调用,代码为: <button onclick="getTextValue()" id="pass_text_values" >Submit</button> function remoteCall(postcode, brand_id, product_type_id) { try { alert("values Inside TRY:\n Postcode = "+postcode+"\
<button onclick="getTextValue()" id="pass_text_values" >Submit</button>
function remoteCall(postcode, brand_id, product_type_id)
{
try
{
alert("values Inside TRY:\n Postcode = "+postcode+"\n Brand = "+brand_id+"\n Product type = "+product_type_id);
var serverUrl = "http://192.168.1.200/kruthika/findenggapi.php?postcode_s="+postcode+"&brand_id="+brand_id+"&product_type_id="+product_type_id;
alert("URL : \n "+serverUrl);
$.ajax({
type: 'GET',
url: serverUrl ,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function(data)
{
if(data == '')
alert("No data received from server");
else
{
for (var i = 0; i < data.length; i++)
{
var disp_data = "name = "+data[i].name+"<br> town = "+data[i].town+"<br> phone = "+data[i].phone+"<br> mobile = "+data[i].mobile+"<br> Email = "+data[i].email+"<hr>";
alert("Data from server = "+disp_data);
}
}//end of else.
},//ens od success.
error: function(xhr, textStatus, errorThrown)
{
alert(xhr.responseText);
alert('FAIL !!!');
},
});//end of AJAX.
}//end of try
catch(e)
{
alert("error = "+e.message);
}
}//END OF FUNC remoteCall.
remotecall函数对服务器进行ajax调用并显示数据,代码为:
<button onclick="getTextValue()" id="pass_text_values" >Submit</button>
function remoteCall(postcode, brand_id, product_type_id)
{
try
{
alert("values Inside TRY:\n Postcode = "+postcode+"\n Brand = "+brand_id+"\n Product type = "+product_type_id);
var serverUrl = "http://192.168.1.200/kruthika/findenggapi.php?postcode_s="+postcode+"&brand_id="+brand_id+"&product_type_id="+product_type_id;
alert("URL : \n "+serverUrl);
$.ajax({
type: 'GET',
url: serverUrl ,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function(data)
{
if(data == '')
alert("No data received from server");
else
{
for (var i = 0; i < data.length; i++)
{
var disp_data = "name = "+data[i].name+"<br> town = "+data[i].town+"<br> phone = "+data[i].phone+"<br> mobile = "+data[i].mobile+"<br> Email = "+data[i].email+"<hr>";
alert("Data from server = "+disp_data);
}
}//end of else.
},//ens od success.
error: function(xhr, textStatus, errorThrown)
{
alert(xhr.responseText);
alert('FAIL !!!');
},
});//end of AJAX.
}//end of try
catch(e)
{
alert("error = "+e.message);
}
}//END OF FUNC remoteCall.
功能远程调用(邮政编码、品牌标识、产品类型标识)
{
尝试
{
警报(“尝试中的值:\n Postcode=“+Postcode+”\n Brand=“+Brand\u id+”\n Product type=“+Product\u type\u id”);
var serverUrl=”http://192.168.1.200/kruthika/findenggapi.php?postcode_s=“+邮政编码+”&品牌标识=“+品牌标识+”&产品类型标识=“+产品类型标识”;
警报(“URL:\n”+服务器URL);
$.ajax({
键入:“GET”,
url:serverUrl,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(数据)
{
如果(数据=“”)
警报(“未收到来自服务器的数据”);
其他的
{
对于(变量i=0;itown=“+data[i].town+”
phone=“+data[i].phone+”
mobile=“+data[i].mobile+”
Email=“+data[i].Email+”
;
警报(“来自服务器的数据=”+显示数据);
}
}//别想了。
},//成功了。
错误:函数(xhr、textStatus、errorshown)
{
警报(xhr.responseText);
警报('FAIL!!!');
},
});//AJAX的结束。
}//尝试结束
捕获(e)
{
警报(“错误=”+e.message);
}
}//FUNC远程调用结束。
如果我在外部调用相同的remotecall函数,那么它可以工作,但是如果我用onclick调用它,它就不工作了。任何人都可以帮忙。尝试添加选项
async:false
给你打电话。。那么它可能会起作用。您确定var用户的邮政编码、品牌id和产品类型id是好的吗?错误是什么?:非常感谢……:)我现在可以得到输出了。我能够提醒结果。但我想知道结果。我为此添加了以下代码:document.getElementById(“engg\u details”).innerHTML=final\u disp\u data;但它不起作用。。。你能帮忙吗请…试试这个。。。这可能会有帮助:别忘了接受答案:)谢谢你,伙计,你让我开心了非常感谢……:)提交,这解决了我的问题……)