douxi2011 2016-05-01 10:13
浏览 46
已采纳

如何使用jquery将数据从PHP传输到Javascript? [重复]

This question already has an answer here:

I want to transfer data from PHP page which import data from MySql, so I need to show this data on my mobile app (Cordova), I use javascript.

this is the PHP code which I use:

if($count == 1) {
          echo $name .$points . $gold;
          
      }else {
         echo "Your Login Name or Password is invalid";

      }

and this is the Jquery code:

$.ajax({
    type: 'POST',
    url: 'http://xxxxxx/login.php',
    data: datastring,
    success: function(data) {
        alert(data + 'worked');//     does nothing
    }
});

</div>
  • 写回答

1条回答 默认 最新

  • duanpan3166 2016-05-01 10:23
    关注

    I found the answer:

    1- add 'json_encode' after 'echo' 2- use this code on Javascript:

    <script>
        function reqListener () {
          console.log(this.responseText);
        }
        var oReq = new XMLHttpRequest();
        oReq.onload = function() {
            alert(this.responseText);
        };
        oReq.open("get", "http://localhost/send.php", true);
        oReq.send();
    </script>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器