2017-03-01 59 views
0

如何使用php在Intel-xdk中显示来自MySQL的图像。请如何使用ajax请求在英特尔xdk中显示图像? 我试图检索只显示文本而不是图像的信息。 我使用PHP,当我请求的信息只有文本正在显示。 这里是我用来检索数据如何使用php在Intel-xdk中使用php显示MySQL中的图像

function showUser() { 

       if (window.XMLHttpRequest) { 
        // code for IE7+, Firefox, Chrome, Opera, Safari 
        xmlhttp = new XMLHttpRequest(); 
       } else { 
        // code for IE6, IE5 
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 

       xmlhttp.onreadystatechange = function() { 
        if (this.readyState == 4 && this.status == 200) { 
         document.getElementById("list").innerHTML = this.responsetext; 

        } 
       }; 
       xmlhttp.open("GET", "http://localhost/SaltCity/index.php",true); 
       xmlhttp.send() 
      } 
+0

请分享一些代码... – hering

+0

请我添加的代码我用来检索信息 – tyma

+0

您是否下载混合内容?如果您要将图片作为文本下载,则必须使用base64编码您的响应,然后以此方式显示。如果您正在下载html,那么您只需将其呈现为html并检查所有链接是否已正确引用。 –

回答

0

代码这里的PHP在JSON返回一个文件名。这假定您将文件名存储在MySQL中名为profileimage的字段中,并且您的php的名称是getprofileimage.php。

$result = $conn->query("select profileimage from profiles where userid = '" . $userid . "'"); 

$outp = "["; 
while($rs = $result->fetch_array(MYSQLI_ASSOC)) { 
    if ($outp != "[") {$outp .= ",";} 
    $outp .= '{"profileimage":"' . $rs["profileimage"] . '"}'; 
} 
$outp .="]"; 

运行时,它返回一个JSON字符串这样

[{ 
    "profileimage": "abcd.jpg" 
}] 

在JavaScript中,做到这一点:

function getProfile(){ 
    var url = "http://yourserverlocation.com" + "/getprofileimage.php"; 

    $.ajax({ 
     url: url, 
     type: 'GET', 
     data: JSONObject, 
     dataType: 'json', 
     contentType: "application/json; charset=utf-8", 
     success: function (arr) { 
      _getProfileResult(arr); 
     }, 
     error: function() { 
      validationMsg(); 
     } 
    }); 
} 

function _getProfileResult(arr){ 
    profileimage = arr[0].profileimage; 
    //assuming that you have a <img id="imgProfilePicture> tag 
    $("#imgProfilePicture").attr("src","http://yourserverlocation.com/" + "/images/" + profileimage +"_s");  
} 
+0

我只存储文件名,请我急需帮助。先谢谢你 – tyma