使用 ajax 脚本传递 base 64 字符串
Pass base 64 string using ajax script
我使用以下脚本将字符串 url 传递到另一个 php 页面。
function saveIt(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert("Save successfully!");
}
}
var value1 = document.getElementById("url").value ;
var value2 = document.getElementById("time").value;
var value3 = document.getElementById("note").value;
xmlhttp.open("POST", "insertFrame.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("url="+ value1 + "&time=" + value2 + "¬e=" + value3);
}
之后,我将检索到的数据插入 table
$url = $_POST['url'];
$time = $_POST['time'];
$note = $_POST['note'];
mysql_connect("localhost", "root", "");
mysql_select_db("studioassessor_01");
mysql_query("INSERT INTO frame VALUES ('$url', '$time', '$note')");
但是,当我想从数据库中检索 url 以显示图像时,它失败了并且看起来已损坏。
<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("studioassessor_01");
$sql = mysql_query("SELECT * FROM frame");
while($row = mysql_fetch_array($sql)){
echo '<img src="' . $row['url'] . '">';
echo "<br/><br/>";
echo $row['note'];
}
?>
在我更改代码并进行测试后,我发现 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");是使我的 url 在传递到另一个 php 页面并存储在数据库中时变成不同值的可能原因。我可以知道我该如何解决这个问题吗?
我已经使用 str_replace(' ', '+', "your string") 解决了我的问题。这是因为编码时的字符串值将全部更改为 space 并且缺少 + 号。因此,我需要将其替换回去以取回正确的 url 值并显示图像。谢谢。
我使用以下脚本将字符串 url 传递到另一个 php 页面。
function saveIt(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert("Save successfully!");
}
}
var value1 = document.getElementById("url").value ;
var value2 = document.getElementById("time").value;
var value3 = document.getElementById("note").value;
xmlhttp.open("POST", "insertFrame.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("url="+ value1 + "&time=" + value2 + "¬e=" + value3);
}
之后,我将检索到的数据插入 table
$url = $_POST['url'];
$time = $_POST['time'];
$note = $_POST['note'];
mysql_connect("localhost", "root", "");
mysql_select_db("studioassessor_01");
mysql_query("INSERT INTO frame VALUES ('$url', '$time', '$note')");
但是,当我想从数据库中检索 url 以显示图像时,它失败了并且看起来已损坏。
<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("studioassessor_01");
$sql = mysql_query("SELECT * FROM frame");
while($row = mysql_fetch_array($sql)){
echo '<img src="' . $row['url'] . '">';
echo "<br/><br/>";
echo $row['note'];
}
?>
在我更改代码并进行测试后,我发现 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");是使我的 url 在传递到另一个 php 页面并存储在数据库中时变成不同值的可能原因。我可以知道我该如何解决这个问题吗?
我已经使用 str_replace(' ', '+', "your string") 解决了我的问题。这是因为编码时的字符串值将全部更改为 space 并且缺少 + 号。因此,我需要将其替换回去以取回正确的 url 值并显示图像。谢谢。