问题
I've a basic code in xdk. An app with one button and the code for that button is :
$.post("http://url/test.php", {test:'1'},
function(res){
alert(res);
}
);
For testing purpose, I've a php code in a godaddy server.
The php code is :
<?php
if (isset($_POST['test'])){
if ($_POST['test'] = '1')
echo "AOK";
else
echo "NOK1";
}
else
echo "NOK2";
When I run this as 'emulate' in XDK and press the button, I am getting
NOK2
as my output.
What is going wrong or what am I missing ?
Update
The same code how-ever works for GET, and the output is
AOK
Php Code :
<?php
if (isset($_GET['test'])){
// echo var_dump($_GET) ;
if ($_GET['test'] = '1')
echo "AOK";
else
echo "NOK1";
}
else{
//echo var_dump($_POST) ;
echo "NOK2";
}
jQuery:
$.ajax({
type: "GET",
url: 'http://url/test.php',
data:{test:'1'},
success: function(res){alert(res);},
error:function(res){alert(res);},
dataType: 'text'
});
Replacing GET with POST causes the problem.
回答1:
You have a bug in your code fix this and check if it work. I just verified that POST request work with intel XDK. In the following line you have a mistake.
if ($_POST['test'] = '1')
in case you could not figure it out here is what it is supposed to be.
if ($_POST['test'] == '1')
来源:https://stackoverflow.com/questions/30252973/post-doesnt-work-in-intel-xdk