Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将jquery变量转换为php变量_Php_Jquery_Mysql - Fatal编程技术网

将jquery变量转换为php变量

将jquery变量转换为php变量,php,jquery,mysql,Php,Jquery,Mysql,我将以下代码作为jQuery脚本的一部分,在div中显示结果 var html = ""; //Displaying profile if (options.display_profile) { html += "<div class='instagram_profile'" + styles.profile_container + ">"; html += "<img class='inst

我将以下代码作为jQuery脚本的一部分,在div中显示结果

var html = "";
//Displaying profile
if (options.display_profile) {
    html += "<div class='instagram_profile'" + styles.profile_container + ">";
    html += "<img class='instagram_profile_image' src='" + data.profile_pic_url  + "' alt='"+ (is_tag ? data.name + " tag pic" : data.username + " profile pic") + "'" + styles.profile_image + (options.lazy_load ? " loading='lazy'" : '') + " />";
    if (is_tag)
        html += "<p class='instagram_tag'" + styles.profile_name + "><a href='https://www.instagram.com/explore/tags/" + options.tag + "' rel='noopener' target='_blank'>#" + options.tag + "</a></p>";
    else
        html += "<p class='instagram_username'" + styles.profile_name + ">@" + data.full_name + " (<a href='https://www.instagram.com/" + options.username + "' rel='noopener' target='_blank'>@" + options.username + "</a>)</p>";

    if (!is_tag && options.display_biography)
        html += "<p class='instagram_biography'" + styles.profile_biography + ">" + data.biography + "</p>";

    html += "</div>";
}
var html=”“;
//显示配置文件
如果(选项。显示\u配置文件){
html+=“”;
html+=“”;
if(is_标签)
html+=“

”; 其他的 html+=“

@“+data.full\u name+”()

”; 如果(!is_tag&&options.display_) html+=“

“+data.传记+”

”; html+=“”; }
现在我想将结果传递到一个php变量中,这样我就可以将它传递到一个mysql表中,而不是在

<div id='instagram-feed3' class='instagram_feed'></div>


还有其他方法吗?

正如@Barmar在评论中建议的那样,您需要执行一个AJAX调用(由jQuery$.post()和$.AJAX()支持)。 提交数据时,您可以使用$_POST[“name_of_var”](这是存储POST值的PHP变量)在PHP中获取变量

这是一个关于如何做到这一点和你需要知道的一切伟大的教程

但是:想想看,您喜欢将HTML存储在数据库中。那为什么这不是个好主意呢

数据库的一条重要规则是:不应保存可以从存储的数据计算的所有内容。当您这样做时,您将保持数据的动态性—当您这样做时,您只需更改一个变量即可影响其他计算的结果。 存储整个计算出的HTML将使以后编辑它变得非常困难。 用户是否更改其.profile\u pic\u url?更新数据库表中的单元格,让JS计算新的前端(是的,每次用户查看该内容时)。 将HTML保存在前端,将来,您将为此感谢自己。在某些情况下,您可以在服务器站点上创建一些HTML,在某些情况下,只要它是动态的且易于修改,就完全可以了

结论:尽可能保持代码的动态性,以使将来的工作更轻松。
考虑使用用户数据创建一个表,并根据该数据计算前端。

您需要提交一个表单或使用AJAX。在Google逐字输入您的问题标题,可能已经得到很多结果。在你问这个问题之前,请先做一点基础研究。