0

I have a PHP file that uploads a video to microsoft azure service through an api , which returns an object (StdObject) file. I want to send that back through ajax back to javascript. The video is successfully getting uploaded to azure, so no problems on that side. But when I try to see what is inside the "asset" object in js, its just empty. php vardump of the asset file is showing the contents properly. What am i doing wrong here ?

Here is my JS code:

var asset;
$.ajax({
        type: "POST",
        url: "internal_api/uploadasset.php",
        cache: false,
        processData: false,
        contentType: false,
        data: form_data,
        success: function(data){
            rowid = data.rowid;
            asset = data.videoasset;
            console.log(asset);
            alert("Video successfully uploaded");
        },
        error: function() {
            alert("Error");
        },
        dataType: 'json',
    });

PHP code:

<?php
    require_once '../vendor/autoload.php';
    include './config.php';
    include_once 'azureconfig.inc';
    use WindowsAzure\Common\ServicesBuilder;
    use WindowsAzure\Common\Internal\MediaServicesSettings;
    use WindowsAzure\Common\Internal\Utilities;
    use WindowsAzure\MediaServices\Models\Asset;

    /*
       all azure code comes here
    */
    $videoAsset = uploadFileAndCreateAsset($restProxy,$video_file,$video_name);
    $query = mysql_query("insert into tbl_videos (filename,userid,clipid,type).....")
    $rowid = mysql_insert_id();
    $return['rowid'] = $rowid;
    $return['videoasset'] = $videoAsset;

    echo json_encode($return);
?>
Rangarajan K
  • 93
  • 3
  • 14
  • 4
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Jul 18 '17 at 09:16
  • 1
    Debugg the php code to see if it works - turn on error reporting and check you `$return` content before encoding it. – Peon Jul 18 '17 at 09:17
  • 1
    What is in `$videoAsset`? – RiggsFolly Jul 18 '17 at 09:18
  • 1
    check what `uploadFileAndCreateAsset()` is returning – Chris Lam Jul 18 '17 at 09:19
  • its a standard php class object (http://php.net/manual/en/language.types.object.php) with some methods, variables – Rangarajan K Jul 18 '17 at 09:37
  • Show us AN EXAMPLE! You say it has methods? – RiggsFolly Jul 18 '17 at 09:42
  • okay sorry.. I had thought the structure of the object would not matter.. here is the definition of it https://github.com/Azure/azure-sdk-for-php/blob/master/src/MediaServices/Models/Asset.php – Rangarajan K Jul 18 '17 at 09:52

1 Answers1

1

Implement the The JsonSerializable interface to the class from which the object returned by the function uploadFileAndCreateAsset() is created.