[英]$_POST variable doesn't work in php Titanium
我试图在JS文件和PHP文件之间传递数据,但PHP中的变量$_POST
不起作用,为此我无法在应用程序中进化!
JS代码:
var params = String(input.value);
var xhr = Titanium.Network.createHTTPClient();
xhr.open('GET','http://10.0.2.2/jobfinder/teste_demo_grafica/Resources/teste.php');
xhr.send(params);
xhr.onload = function(){
var response = this.responseText;
alert(response);
if (response != null)
{
alert("voltou ao js e funca");
}
else
{
alert("-.-");
}
};
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.onerror = function(e){alert('Transmission error: ' + e.error);};
});
现在的PHP代码:
<?php
// Connect to the database(host, username, password)
$con = mysql_connect('localhost','root','');
if (!$con)
{
return ("Failed to make connection.");
exit;
}
// Select the database. Enter the name of your database (not the same as the table name)
$db = mysql_select_db('jobfinder');
if (!$db)
{
echo "Failed to select db.";
exit;
}
$pesquisa= $_POST[params];
echo "pesquisa";
$sql = "SELECT * FROM oferta WHERE titulo like '%$pesquisa%'";
$query = mysql_query($sql);
if (mysql_num_rows($query) > 0)
{
$row = mysql_fetch_array($query);
$response = array(
'titulo' => $row['titulo'],
'oferta' => $row['descricao_oferta']
);
json_encode($response);
echo $response['titulo'];
}
else
{
// Else the username and/or password was invalid! Create an array, json_encode it and echo it out
$response = array(
'message' => 'Não existem ofertas para esta pesquisa'
);
json_encode($response);
}
echo "php mode off";
?>
猜测,您的JavaScript是通过GET发送数据:
xhr.open('GET','http://10.0.2.2/jobfinder/teste_demo_grafica/Resources/teste.php');
但你的PHP正在寻找POST。 将POST更改为GET,它可能会起作用。 或相反亦然
我现在有解决方案! 如果我们看到这部分代码:
var params = String(input.value);
** var xhr = Titanium.Network.createHTTPClient();
xhr.open('GET','http://10.0.2.2/jobfinder/teste_demo_grafica/Resources/teste.php');
xhr.send(params);
xhr.onload = function(){**
var response = this.responseText;
alert(response);
if (response != null)
{
alert("voltou ao js e funca");
}
else
{
alert("-.-");
}
};
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.onerror = function(e){alert('Transmission error: ' + e.error);};
});
**之间的密码是问题...所以我喜欢这样:
var url = "http://10.0.2.2/jobfinder/tessssssste/Resources/teste.php";//bug do titanium resolvido
var params = "?params=" + input.value;
var encodedURI = encodeURI(url + params);
var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET", encodedURI);
xhr.send();
xhr.onload = function(){
现在它工作TY EVERYBODY !!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.