我無法爲我的生活弄清楚這段代碼中的什麼是擺脫&。如果有人輸入像http://example.com/?ref=me&id=1
這樣的URL,我需要將整個URL顯示在回顯中。但是它會在&之後切斷所有內容。我的代碼中的某些內容忽略了&符後面的所有內容
以下是正在使用的代碼。
HTML:
<div class="toolbar">
Enter the site URL that people will go to when they click your banner and click update to store it:<br>
<input id="ban<?php echo $key;?>" type="text" value="" size="100"> <input type="button" class="buttonHAdd" value="Update" onclick="updateBannerURL('<?php echo $directoryfile ;?>', 'ban<?php echo $key;?>')"><br>
Use the following HTML to display the banner on your site:<br><span id="htmlban<?php echo $key;?>" style="background-color: #ffffff"></span>
</div>
腳本:
function updateBannerURL(bannerFile, id) {
if($("#"+id).val() == "") {
alert("You have not entered a site url");
return;
}
$.ajax({
type: "POST",
url: "update.banner.php",
data:'m='+$('#memberId').val()+'&b='+bannerFile+'&u='+$("#"+id).val(),
dataType: 'json',
success: function(data, textStatus) {
$('#html'+id).text(data.bannerHtml);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('.workareaTip').html('Hmm... Looks like an error occurred.');
}
});
}
PHP文件update.banner.php
<?php
$domain = 'https://example.com/banner';
$u = $_POST['u'];
$b = $_POST['b'];
$m = $_POST['m'];
$array = array('bannerHtml'=>
'<a href="'.$u.'"><img src="'.$domain.'/banners/'.$m.'/'.$b.'" border=""/><a/>'
);
echo json_encode($array);
?>
與該代碼,我可以輸入:http://example.com/?ref=me&id=1
這裏是什麼它迴應:http://example.com/?ref=me
完全無視&符號後的所有內容。
我建議你使用'數據:{M:$(「#MEMBERID」 ).val(),b:bannerFile,u:$(「#」+ id).val()}'。 – PiLHA