简体   繁体   English

发送一个jQuery var到php var

[英]Sending a JQuery var into php var

I installed OpenCart CMS and wanted to modify some option in the admin panel mainly the look and feel of the template. 我安装了OpenCart CMS,想要修改管理面板中的某些选项,主要是模板的外观。 I also added the jpicker script for color picking. 我还添加了jpicker脚本以进行颜色选择。 Also i created the css file with the standard php code and it works fine 我也用标准的PHP代码创建了css文件,它工作正常

<?php header("Content-type: text/css; charset: UTF-8"); ?>

<?php 
        $headerColor;
        $menuColor = '#121212';
        $bodyColor = '#fffaaa';

?>

    #header {
        background-color: <?=$headerColor; ?>;
    }

In order to create the color picker view you need to add the id of the div in a script 为了创建颜色选择器视图,您需要在脚本中添加div的ID

$(document).ready(function(){
  $('#Expandable').jPicker(
    {
      window:
      {
        expandable: true
      }
    });
 });

And here is the standard code for the html 这是html的标准代码

<div id="Expandable"></div>

I am not very good at JQuery but i know that it can be done either with .ajax or post. 我不太擅长JQuery,但我知道可以使用.ajax或post完成。 What i want to do is send the hex value from the jpicker to a php variable in the css file so it can change the color. 我想做的是将十六进制值从jpicker发送到css文件中的php变量,以便它可以更改颜色。 Here is the link to jpicker http://www.digitalmagicpro.com/jPicker/ . 这是jpicker的链接http://www.digitalmagicpro.com/jPicker/ I also found an example 我也找到了一个例子

  var colorValue = '#ababab';
  $.post("view/stylesheet/stylesheet-template.css", {var_value: colorValue}, function(data) {
    alert(colorValue);
});

It only sends alert and the colorValue from the variable, but i still don't know how to send the colorValue to php from the jpicker. 它仅从变量发送警报和colorValue,但我仍然不知道如何从jpicker将colorValue发送到php。

Thanks 谢谢

function sendToPhp(jCell){
$.ajax({
    url: "php/ajax.php",
    data: {cell: jCell, queryNr: "0"},
    type: "POST",
    async: false,
    success: function(data){ callback(data); }
    });
}

now cell and queryNr is sent to php 现在单元格和queryNr发送到php

if u do a switch case function depending on query nr you can access multiple functions in php this way 如果您根据查询nr做一个开关案例功能,您可以通过这种方式在php中访问多个功能



for the comment: 的评论:

function sendToPhp(jCell, phpUrl){
$.ajax({
    url: phpUrl,
    data: {cell: jCell, queryNr: "0"},
    type: "POST",
    async: false,
    success: function(data){ callback(data); }
    });
}

now you can hand over a specific path by calling the function like: 现在您可以通过调用以下函数来传递特定路径:

sendToPhp("VAR YOU WANT TO SEND TO PHP", "php/ajax.php"); // or any other path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM