douxiuar885064 2013-06-09 14:51
浏览 23

将JQuery var发送到php var

I installed OpenCart CMS and wanted to modify some option in the admin panel mainly the look and feel of the template. I also added the jpicker script for color picking. Also i created the css file with the standard php code and it works fine

<?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

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

And here is the standard code for the 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. 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. Here is the link to 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.

Thanks

  • 写回答

1条回答 默认 最新

  • dou44481 2013-06-09 15:09
    关注
    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

    if u do a switch case function depending on query nr you can access multiple functions in php this way



    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?