简体   繁体   English

从 API 到 Cordova 的返回值(通过文件传输)

[英]Return Value from API to Cordova (Via File Transfer)

Hi I'm trying to return a value from a API call via the file transfer plugin for cordova.嗨,我正在尝试通过cordova 的文件传输插件从API 调用返回一个值。 I've shown below my php code for the API which is working fine and the Cordova code.我已经在我的 php 代码和 Cordova 代码下面显示了运行良好的 API 代码。 Essentially what I want to do is turn the return statement in the API into a JS variable in Cordova.本质上我想要做的是将 API 中的 return 语句转换为 Cordova 中的 JS 变量。 This is the Php code, the move_uploaded_file part works fine:这是 PHP 代码, move_uploaded_file 部分工作正常:

    protected function uploadPicturesAction()
    {
    move_uploaded_file($tmp_name, "/home/sean/images/{$name}.jpg");
    return $name;
    }

This is the cordova part, so here I am trying to get the variable $name to become a JS variable.这是cordova部分,所以在这里我试图让变量$name成为一个JS变量。

    fileTransfer.upload(image, encodeURI("sean.co.uk/api.php?action=uploadPictures"), imagePage2(), fail, options);

Any help would be much appreciated.任何帮助将不胜感激。

  1. Create a PHP file (eg loadpics.php ) that contains the function uploadPicturesAction either through including a library file or just hard coded.创建一个包含函数uploadPicturesAction的 PHP 文件(例如loadpics.php ),或者通过包含一个库文件或者只是硬编码。
  2. To that file add as last line: echo uploadPicturesAction();将该文件添加为最后一行: echo uploadPicturesAction();
  3. In your javascript use ajax to call loadpics.php and assign the return value to your javascrpt variable.在您的 javascript 中,使用 ajax 调用loadpics.php并将返回值分配给您的 javascrpt 变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM