$ .Post在Intel XDK中不起作用 [英] $.Post doesn't work in Intel XDK

查看:63
本文介绍了$ .Post在Intel XDK中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在xdk中有一个基本代码. 带有一个按钮的应用程序,该按钮的代码为:

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);
            }
       );

出于测试目的,我在godaddy服务器中安装了一个php代码.

For testing purpose, I've a php code in a godaddy server.

php代码是:

<?php
if (isset($_POST['test'])){
   if ($_POST['test'] = '1')
       echo "AOK";
   else
      echo "NOK1";
}
else
    echo "NOK2";

当我在XDK中以模拟"方式运行它并按下按钮时,我得到

When I run this as 'emulate' in XDK and press the button, I am getting

NOK2

NOK2

作为我的输出.

出了什么问题或我想念什么?

What is going wrong or what am I missing ?

更新

相同的代码可用于GET,输出为

The same code how-ever works for GET, and the output is

确定

Php代码:

<?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'
        });

用POST替换GET会导致问题.

Replacing GET with POST causes the problem.

推荐答案

您的代码中存在一个错误,请解决此问题并检查其是否有效.我刚刚验证了POST请求可与Intel XDK一起使用. 在下面的行中,您有一个错误.

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')

这篇关于$ .Post在Intel XDK中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆