在PHP echo中嵌入javascript [英] Embed javascript in PHP echo

查看:81
本文介绍了在PHP echo中嵌入javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

echo "<td> + manuf + </td>";

以上是否会起作用?

我从mysql数据库中提取结果来编辑内容但是需要jQuery功能来编辑它,因此嵌入的javascript变量......

I'm pulling results from a mysql db to edit the contents but need the jQuery functionality to edit it, hence the embedded javascript variable...

编辑:

很抱歉缺乏上下文,这与我在这里提出的另一个问题有关 Mysql编辑用户已下达的订单
这是最终目标。要编辑我下的订单,我需要将结果拉入类似于用户下订单的环境。所以我的想法是包括jQuery功能将项目添加到购物车等,然后他们可以按提交和我使用相同的方式.Ajax将数据发布到插入PHP脚本我会将值发布到更新PHP脚本!这是倒退的想法,欢迎任何建议!

Sorry for the lack of context, its related to another question i've asked on here Mysql edit users orders they have placed this is the end goal. To edit the order i place, i need to pull the results into an environment similar to how the user placed the order. So my thinking was to include the jQuery functionality to add items to a cart etc, then they could press submit and in the same way i used .Ajax to post the data to an insert php script i would post the values to an update php script! Is this backwards thinking, any advice welcomed!

推荐答案

我建议你看看下面的内容。

I suggest you take a look at the follwing.

  • json_encode
  • Ajax
  • JSONP

现在你最简单的解决办法就是去做一个 json_encode 方法。让我举个例子:

Now your simplest solution under you circumstances is to do go for the json_encode method. Let me show you an example:

$json_data = array(
    'manuf' => $some_munaf_data
);

echo "<script type=\"text/javascript\">";
   echo "var Data = " . json_encode(json_data);
echo "</script>";

这将生成一个名为 Data 的对象,并且看起来像这样:

This will produce an object called Data, and would look like so:

<script type="text/javascript">
var Data = {
    munaf : "You value of $some_munaf_data"
}
</script>

然后当您需要数据时,只需使用 Data.munaf ,它将保留PHP端的值。

Then when you need the data just use Data.munaf and it will hold the value from the PHP Side.

这篇关于在PHP echo中嵌入javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆