php - 如何使用 php 在 Intel-xdk 中显示来自 MySQL 的图像

标签 php mysql intel-xdk

如何使用 php 在 Intel-xdk 中显示来自 MySQL 的图像。请问如何使用ajax请求在Intel xdk中显示图像? 我试图检索仅显示文本而不显示图像的信息。 我使用 php,当我请求信息时,仅显示文本。 这是我用来检索数据的代码

   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()  
            }

最佳答案

这是返回 JSON 格式的文件名的 PHP。假设您将文件名存储在 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");     
}

关于php - 如何使用 php 在 Intel-xdk 中显示来自 MySQL 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42527484/

相关文章:

java - 来自 java 的 PHP Soap 请求

php - Zend Framework 和 UTF-8 字符的问题 (æøå)

java - 无法让我的 jsp 存储结果集中的整数值

html - 如何在 intel XDK 中获得 100% 列的高度

android - intel xdk 在后退按钮点击时退出移动应用程序

php - MySqli UPDATE,检测条目是否不存在

php - 组合框在 IE8 中不起作用

java - Spring 数据 : Create entities (and DB entries) using boolean fields of another entity

mysql - 仅比较最新记录

android - Android 的英特尔 XDK 构建错误