2017-07-18 96 views
0

我有一個PHP文件,通過api將視頻上傳到Microsoft Azure服務,該API會返回一個對象(StdObject)文件。我想通過ajax將它發送回javascript。視頻成功上傳到天藍色,所以沒有問題。但是當我試圖查看js中「資產」對象的內容時,它只是空的。資產文件的php vardump正在正確顯示內容。我在這裏做錯了什麼?通過ajax將javascript對象返回給javascript

這裏是我的 JS代碼:

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代碼:

<?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); 
?> 
+4

每次你在新代碼 使用[了'mysql_'(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) 數據庫擴展* * [出現這種情況(https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** 它已被棄用,多年來一直和一去不復返的PHP7。 如果您只是學習PHP,花費精力學習'PDO'或'mysqli'數據庫擴展和準備語句。 [從這裏開始](http://php.net/manual/en/book.pdo.php) – RiggsFolly

+1

Debugg PHP代碼,看看它是否工作 - 打開錯誤報告,並在編碼之前檢查你'$ return'內容。 – Peon

+1

'$ videoAsset'中有什麼? – RiggsFolly

回答

1

落實The JsonSerializable interface從其中由功能uploadFileAndCreateAsset()返回的對象被創建的類。

+0

謝謝...工作 –

+0

不客氣。我很高興它的工作。 – 2017-07-18 13:07:52