Hello o have an html form and a php script and html passes some values with a form in the php script. well here is jquery code
<script type="text/javascript">
$(document).ready(function() {
$('#convert').click(function(){
//pairno tis times ap tin forma
var name = $('#name').val();
var tel = $('#tel').val();
var tel2 = $('#tel2').val();
var street = $('#street').val();
var minconsum = $('#minconsum').val();
var closedtill = $('#closedtill').val();
var opentill = $('#opentill').val();
var city = $('#city').val();
var type = $('#type').val();
if($('#city').val()=='ΑΤΤΙΚΗ')
{
var perioxi = $('#perioxiAtt').val();
}else if($('#city').val()=='ΚΥΠΡΟΣ')
{
var perioxi = $('#perioxiKypr').val();
}else if($('#city').val()=='ΘΕΣΣΑΛΟΝΙΚΗ')
{
var perioxi = $('#perioxiThess').val();
}else{
var perioxi = $('#perioxiGen').val();
}
var dataString = "name=" + name + "&tel=" + tel + "&tel2=" + tel2 + "&street=" + street + "&minconsum=" + minconsum + "&closedtill=" + closedtill + "&opentill=" + opentill + "&city=" + city + "&perioxi=" + perioxi + "&type=" + type;
$.ajax({
type: "POST",
url: "ajax_converter.php",
data: dataString,
success: function(data){
//pairno ta dedomena
$('#results').show();
//vazo ta dedomena sto results div tag.
$('#results').html(data);
}
});
and i get the date in my php script as usual
$name = $_POST['name'];
$tel = $_POST['tel'];
$tel2 = $_POST['tel2'];
$street = $_POST['street'];
$minconsum = $_POST['minconsum'];
$closedtill = $_POST['closedtill'];
$opentill = $_POST['opentill'];
$city = $_POST['city'];
$perioxi = $_POST['perioxi'];
$type = $_POST['type'];
everything works fine except the strange charachters &,<,>, etc so that is my problem!
any help would be really helpfull!
here is my html form at least a part of it where i have the problem
<label for="name">Όνομα:</label>
<input type="text" name="name" id="name" value="" />
I forgot to mention my output if i enter a name like “zo & za” without the quotes i get “zo” that’s all. all the rest of the input string is lost
For the sake of readability I would define the Ajax parameters like below and let jQuery convert it into the querystring for you encoding it properly. Building it manually will cause issues if you had an ‘&’ character in one of the variables for example (Christofer Eliasson’s answer may do this too):