I have this code, but this line has some problem.
var dataString = 'name='+name&'id='+id;
what is sent (firebug):
'id ' id
'name' name
The line above works correctly if i do: var dataString = 'name='+name;
However, i need to pass two parameters. What is the correct way to do that?
code
<script type="text/javascript">
$(function () {
$(".vote").click(function () {
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'name='+name&'id='+id;
if (name == 'up') {
$.ajax({
type: "POST",
url: "url.php",
data: dataString,
cache: false,
success: function (html) {
}
});
return false;
});
});
</script>
You should do:
var dataString = { name: name, id: id}
instead of
var dataString = 'name='+name&'id='+id;
So that you are sure that the supplied values are correctly URI encoded.
Try this:
var dataString = 'name='+name+'&id='+id;
Instead of
var dataString = 'name='+name&'id='+id;
The & should be inside '', and you need extra + to concat "name" variable and '&id=' string. So this should work.
UPD:
You can also do:
var dataString = { name: name, id: id }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With