Hi everybody !
I'm using win7, titanium 3.1.1 alloy
I have a problem with POST method.
I have create a function to insert into Mysql by Alloy and PHP This is my code .js
function transmit(){ var request = Ti.Network.createHTTPClient({ onload: function () { alert(this.responseText); }, onerror: function(e){ Ti.API.debug(e.error); alert('There was an error during the conexion'); }, timeout:1000, }); var params = { title: 'my title 1', summary: 'i am a man', content: 'greate boy', }; request.open("POST","http://localhost/titanium_connect/get2.php"); request.send({ title: 'my title 1', summary: 'i am a man', content: 'greate boy', }); } transmit(); $.index.open();And php code
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } if(isset($_POST['title'])){ $title = $_POST['title']; } else { $title = 'It not working';} if(isset($_POST['title'])){ $title = $_POST['title']; } else { $title = 'title, It not working';} if(isset($_POST['summary'])){ $summary = $_POST['summary']; } else { $summary = 'summary, It not working';} if(isset($_POST['content'])){ $content = $_POST['content']; } else { $content = 'content, It not working';} $sql = "INSERT INTO posts ". "(title, summary, content) ". "VALUES ('".$title."', '".$summary."', '".$content."')"; mysql_select_db('todolist'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfully\n"; mysql_close($conn); ?>I try with GET method request.open("POST","http://localhost/titanium_connect/get2.php?title=" + 'my title'); and it work But it doesn't with POST method, already call get2.php but can't receive params.
What's wrong?