我试图JSON从ajax调用的php页面获取数据.php页面返回AJAX字符串,现在我必须分别获取JSON数据和显示值.
我怎样才能做到这一点???
这里是我正在使用的代码....当我运行此代码以获取数据product_id时,它显示警报未定义.
码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Request json test</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script language="JavaScript">
$(document).ready(function(){
$("#testjson").click(function(e){
startJsonSession();
return false;
});
function startJsonSession(){
$.ajax({
url: "index.php",
cache: false,
dataType: "json",
complete: function(data) {
pid = data.product_id;
alert(pid);
}
});
}
});
</script>
</head>
<body>
<a href="#" id="testjson">Get JSON Data</a>
<div id="showdata"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
index.php的JSON输出:
[{"ID":"1","product_id":"3","image_name":"cycle5.png","image_type":".jpg"},{"ID":"2","product_id":"6","image_name":"cycle3.png","image_type":".jpg"},{"ID":"3","product_id":"4","image_name":"cycle2.png","image_type":".jpg"},{"ID":"4","product_id":"43","image_name":"cycle1.png","image_type":".jpg"},{"ID":"5","product_id":"7","image_name":"cycle8.png","image_type":".jpg"},{"ID":"6","product_id":"9","image_name":"cycle0.png","image_type":".jpg"},{"ID":"7","product_id":"543","image_name":"cycle6.png","image_type":".jpg"},{"ID":"8","product_id":"445","image_name":"cycle9.png","image_type":".jpg"},{"ID":"9","product_id":"453","image_name":"cycle75.png","image_type":".jpg"},{"ID":"10","product_id":"725","image_name":"cycle86.png","image_type":".jpg"}]
Run Code Online (Sandbox Code Playgroud) 这里我试图使用PHP更新mysql表中的更新多个列值.
$product_id = mysqli_real_escape_string($link, $_POST['product_id']);
$product_name = mysqli_real_escape_string($link, $_POST['product_name']);
$product_category = mysqli_real_escape_string($link, $_POST['product_category']);
$sql = "UPDATE product_list (product_name, product_category, product_price,product_description,product_size_category) VALUES ('$product_name', '$product_category', '$product_price', '$product_description', '$size_category')";
}"
Run Code Online (Sandbox Code Playgroud)
我有5个列值要在表中更新,我使用变量来保存数据并使用该变量想要更新表中的值我该怎么做?
在这里,我尝试发送带有一些以粗体突出显示的文本的电子邮件。这是我尝试过的方法,但仍按原样获取标签,但未获取粗体字体。我怎样才能做到这一点?
这是我所做的:
$mail->Body = PROPOSE_STATEMENT." <b>".$product_name."</b> ".REJECTED;
Run Code Online (Sandbox Code Playgroud)
在这里,我使用了<b></b>php中的html 标签来使文本变为粗体,但是我得到的输出是这样的:
you proposed <b>TVS Apache RTR 160</b> Has been
Run Code Online (Sandbox Code Playgroud) 我在myscreen上有一个2弹出窗口,它将一个链接到另一个.当我点击它出现的第二个弹出窗口时,当我关闭弹出窗口时,弹出窗口内容会消失,但背景仍然存在并禁用整个页面.HTML:
<div id="license-temp" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="get-license-popup">
<div class="license-heading">Get License</div>
<br>
<div class="row">
<div class="col-md-5 col-sm-4 col-xs-8">
<div class="license-description reg">What is the duration of the usage?</div>
<div class="duration">
<select id="usage-time">
<option>1 Week - $0.9</option>
<option>1 Weeks - $2.0</option>
<option>1 Month - $5.0</option>
<option>2 Months - $10.0</option>
</select>
</div>
</div>
<div class="col-md-5 col-sm-4 col-xs-8"><div class="license-description reg">What is the preferred return method?</div>
<div class="return-method">
<div><input type="radio" value="auto"> Automatic Return</div>
<div><input type="radio" value="manual"> Manual Return</div>
</div>
</div> …Run Code Online (Sandbox Code Playgroud) 在我的 php 函数中,我想检查会话是否存在。基于会话的存在,我想返回 true 或 false。
我有一个登录函数,它在登录时使用session_start();并将值存储到会话变量中,当注销时它会做session_destroy();
现在我想检查会话是否存在。我怎样才能做到这一点
function ifsessionExists(){
// check if session exists?
if($_SESSION[] != ''){
return true;
}else{
return false;
}
}
Run Code Online (Sandbox Code Playgroud) 我使用存储在 php 数组中的产品 ID 从 db 获取产品的价格。
我有一个 php 函数,我想保存所有购买的产品的总数。在这里,我正在获取购物车商品,并且正在调用应保存总金额的函数。price每次当我从购物车检索产品时,我都会传递该值。
例如,对于第一项迭代,我发送值 300,对于第二项迭代,我发送值 400,对于第三项迭代,我发送值 900。
我想把所有这些加起来并得到总价 1600payableAmount()
我该怎么做?
function getCartitems($product_id){
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT product_id,product_name,product_price,product_image_url FROM product_list WHERE product_id='$product_id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr><td><img class='cart-image img-responsive' src='".$row["product_image_url"]."'></td><td>".$row["product_name"]."</td><td><b>₹ </b>".floor($row["product_price"])."</td><td><a href='mycart.php?action=remove&product_id=".$row['product_id']."'><span class='glyphicon glyphicon-remove'></span> remove</a></td></tr>";
$price = $row['product_price'];
payableAmount($price);
}
} else {
echo "There are no …Run Code Online (Sandbox Code Playgroud) 我想在php中生成20个字符的哈希码并插入到表中,哈希码应该是唯一的.
之后,哈希码可用于访问表中的记录.
<?php
echo uniqid();
//generate 20 charcter alphanumeric id here
?>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我试图在鼠标悬停在表格行上时创建阴影效果。我正在使用伪类 :after 在表格行底部创建阴影效果。我能够获得阴影效果,但我想将伪元素与悬停的行的底部对齐,现在阴影出现在行的顶部,并且它不采用行的确切宽度,它采用屏幕的整个宽度。
我该如何解决这个问题?
这是我所做的。
代码:
.highlight {
box-shadow: 0 2px 18px 0 rgba(0, 0, 0, .5)!important;
background: none;
}
table {
border-collapse: collapse !important;
}
table td {
padding: 10px
}
table tr:hover::after {
box-shadow: 0px 2px 18px 0px rgba(0, 0, 0, 0.5);
content: "";
height: 1px;
left: 15px;
position: absolute;
width: 100%;
z-index: 1 !important;
}Run Code Online (Sandbox Code Playgroud)
<div>
<table border="1px">
<tr>
<td></td>
<td bgcolor="grey">Header1</td>
<td bgcolor="grey">Header2</td>
<td bgcolor="grey">Header3</td>
<td bgcolor="grey">Header4</td>
<td bgcolor="grey">Header5</td>
</tr>
<tr>
<td bgcolor="grey" class="myCell">Row1</td>
<td class="myCell"> …Run Code Online (Sandbox Code Playgroud)我需要获取给定字符串的第一个字符.这里我在会话变量中有一个名字.我将变量值传递substr给获取字符串的第一个字符.但我不能.
我想得到该字符串的第一个字符.
例如John doe.我想得到字符串的第一个字符j.我怎么能用PHP获取它?
<?php
$username = $_SESSION['my_name'];
$fstchar = substr($username, -1);
?>
Run Code Online (Sandbox Code Playgroud) 我是ruby on rails的新手,在这里我试图在Windows 7 64位上的rails上安装ruby.我安装了ruby安装程序,我安装了rails.我还创建了新的应用程序文件.但是当我启动rails服务器时,它显示以下错误.
如何摆脱这些错误并开始开发我的ruby应用程序?
C:\Users\walnut\Desktop > bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies.................
Using rake 10.4.2
Using i18n 0.7.0
Installing json 1.8.3 with native extensions
Gem::InstallError: The 'json' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make …Run Code Online (Sandbox Code Playgroud)