在我的表单中,我想使用项目代码获取项目描述,例如,我将项目描述为 24"存根端 316L SCH10S,其项目代码STUB316LS10SW,因此当我使用STUB316LS10SW在项目代码字段中搜索该特定项目代码的项目描述时,无法获取,因为在项目描述中我有 24 英寸即特殊字符,因此 ajax 没有获取项目描述..你能帮忙
吗 $(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$("#itemcode1").autocomplete({
source: function( request, response ) {
$.ajax({
url: "getProductList.php",
dataType: "json",
data: {
name_startsWith: request.term
},
success: function( data ) {
response($.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") ,
value: item.nameval,
value1: item.toponymName,
price:item.price,
quantity:item.quantity,
prodId:item.prodId,
itemcode:item.itemcode,
}
}));
}
});
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="style1">
<tr>
<td>Item Code </td>
<td> </td>
<td><input type="text" id="itemcode1" name="itemcode1" /></td>
</tr>
<tr>
<td width="125">Products/Description</td>
<td width="10">:</td>
<td width="175"><input name="productDesc1" type="text" id="productDesc1"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="submit" value="Create"
style="width:100px;" id="crt"></td>
</tr>
将带有特殊字符的值(或所有内容)包装到encodeURI()
函数中:http://www.w3schools.com/jsref/jsref_encodeuri.asp
要在JS中解码,请使用:decodeURI()
函数:http://www.w3schools.com/jsref/jsref_decodeuri.asp
要在PHP中解码,请使用rawurldecode()
函数:http://www.php.net/manual/en/function.rawurldecode.php
使用它并编码您的描述,这将接受您的特殊字符。您可能会搜索这个,但不确定您真正想要什么
encodeURIComponent()
或
string rawurlencode ( string $str )
改进您的问题...很难理解