我想删除空白和加号,现在我geting "Individual House"
,我想通过AJAX将此值传递到下一页,还有一些额外的东西:如何删除空格,并加上此代码使用jquery
searchProperties?propertyType=%5B%22
Individual
+
House
%22%2C%22
+
House
%22%5D
我想通过AJAX数据URL是这样的:
searchProperties?propertyType="["Individual House","Row House"]"
function createJSON() {
property_type = [];
$('#property_type:checked').each(function() {
//property_type.push($(this).val());
property_type.push(jQuery.trim($(this).val().replace(/\s+/g, ' '))); // ["Individual+House","Row+House"]
});
var property_typejson = JSON.stringify(property_type),
data = {};
if(property_type != '')
data['propertyType'] = property_typejson;
console.log(data);
$.ajax({
type: 'GET', \t
url: "map.php",
data: data,
success: function (data) {
console.log(data);
},
error: function (errMsg) {
console.log(errMsg);
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<input type="checkbox" id="property_type" name="property_type[]"
value="Individual House" /> Individual House
<input type="checkbox" id="property_type" name="property_type[]"
value="Row House" /> Row House
<input type="checkbox" id="property_type" name="property_type[]"
value="Villa" /> Villa
<br></br>
<button type="button" onClick="createJSON()">
<i class="fa fa-search"></i>Update search
</button>
你准确的问题是什么?你想传递的不是JSON,因为字符串没有被引用。 –
我的问题是,当传递(下一页)的值,我想删除空格和%和+ –
我不认为你这样做。 '%5B' =='['必须编码,因为它是URL中的特殊字符。 –