PHP和省道之间发送数据 [英] Send data between php and dart

查看:118
本文介绍了PHP和省道之间发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我要把镖客户方和使用AJAX的PHP服务器端之间的通信。因为直接执行是不可能的。我编译镖成JavaScript,然后一个Apache服务器上运行它。

So i am trying to communicate between dart clientside and a php server side using AJAX. Since direct execution is not possible. I compiled the dart to javascript and then run it on a apache server.

JSON数据在客户端产生的,但没有从服务器

json data is generated at client end, But there is no response from the the server

镖code

import 'dart:html';
import 'dart:json';

void main() {
  query("#clicker").on.click.add(callServer);

}

void callServer(Event event) {
  var data ={ 'name':"sendname"}
  ,jsondata=stringify(data);
  print(jsondata);

  var req = new HttpRequest();
  req.open('post','http://localhost:8080/darttest/server.php',true);
  //req.setRequestHeader('Content-type','application/json');
  req.send(jsondata);
  print(req.responseText);
}

PHP端,我只是回应接收到的内容。

php side i just echo the content received

<?php

$name = $_POST['name'];
echo $name;

?>

这是我第一次尝试在飞镖节目,所以让我知道,如果这种做法甚至有可能

This is my first try at dart programming, so do let me know if this approach is even possible

推荐答案

要读取响应,你必须把你的code在回调的 readyStateChange

To read the response, you have to put your code in a callback on readyStateChange :

var req = new HttpRequest();
req.open('post','http://localhost:8080/darttest/server.php',true);
req.on.readyStateChange.add((e){
  if (req.readyState == HttpRequest.DONE && req.status == 200){
    print(req.responseText);
  }
});
req.send(jsondata);

用c HTTP请求的$ C $,当你试图读取响应没有处理。你必须等待完成的请求来读取响应。

With your code the http request was not processed when you tried to read the response. You have to wait the completion of the request to read the response.

这篇关于PHP和省道之间发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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