简体   繁体   中英

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. I've shown below my php code for the API which is working fine and the Cordova code. Essentially what I want to do is turn the return statement in the API into a JS variable in Cordova. This is the Php code, the move_uploaded_file part works fine:

    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.

    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.
  2. To that file add as last line: echo uploadPicturesAction();
  3. In your javascript use ajax to call loadpics.php and assign the return value to your javascrpt variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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