我正在尝试传递一个变量,该变量可能包含“+”号,但是传入下一页后,它将被连接起来。
假设我传递'2+2‘,从first.php到second.php on second.php,它看起来是’2.2‘,但我只需要它作为'2+2’。“2-2”也是正确的。这是我的first.php
<script>
$(document).ready(function() {
$("#sub").click(function() {
var txt1 = $("#userquery").val(); //textbox value
$.ajax({
type: "POST",
url: "second.php",
cache: false,
data: "txt1=" + txt1,
dataType: "html",
success: function(result) {
$("#sqlresult").html(result);
}
});
});
});
</script>
<textarea id='userquery' rows='5' cols='115' spellcheck='false' wrap='off' placeholder='Write SQL query here..'></textarea>
<input id='sub' type='submit' value='Execute' title='Ctrl+Enter'>
<hr><div id='sqlresult'><?php include('second.php'); ?></div>发布于 2016-08-03 11:24:47
您正在为data传递一个字符串,这意味着您要对它进行正确的编码(但不是正确地编码)。在URI编码中,+表示空间。
只需将其作为对象传递,jQuery将为您处理正确的编码:
data: {txt1: txt1}发布于 2016-08-03 11:24:18
在像url参数一样传递值之前,必须先对值进行url编码。
var txt1 = encodeURIComponent($("#userquery").val()); 发布于 2016-08-03 11:23:15
试着像这样
"text"+ '+' + "text2"https://stackoverflow.com/questions/38742126
复制相似问题