Hello i want to use Jquery ajax
echo "$(document).ready(function() {
$(\"#submit\").click(function(){
var n = $(\"#n\").val();
jQuery.ajax({
type: \"GET\",
url: \"function.php\",
data: \"n=\"+n,
success: function(results)
{
alert(n);
}
});
});
});";
but never it shows the alert(n);
Can you help me?
Edit: I try to do it with only js but dont work too.. here is it.
<script>
var n = $('#n').val();
$(document).ready(function() {
$('#submit').click(function(){
var n = $("#n").val();
$.ajax({
type: 'GET',
data: "n=" + n,
url: 'function.php',
success: function (results) {
alert(results);
alert("some");
}
});
});
});
</script>
<form action='' method='post'>
<select name='n' id='n'>
<option value='Lusiana'>Lusiana</option>
</select>
<input id='submit' name='submit' type='submit' value='Go'>
</form>
I'm using this code: https://github.com/papalevski/jQuerySlider/tree/master/jQuerySlider
the php is:
<?php
$n = ( isset($_GET['n']) ? $_GET['n'] : "");
echo $n;
?>
please, indent your code, it will be less difficult to read, data should be sent like data: {n:"value"}
, in your case i think this must work data:{n:\""+n+"\"},
echo "$(document).ready(function() {
$('#submit').click(function(){
var n = $('#n').val();
jQuery.ajax({
type: 'GET',
url: 'function.php',
data: {n:n},
success: function(results){
alert(n)
}
});
});
});";
Place your script code inside Nowdocs block, It will be more easier for you to read and/or debug,
The benefit is, you don't have to escape those characters as double quotes and/or single quotes.
Read about it more here
$now = <<<'SCRIPT'
$(document).ready(function() {
$("#submit").click(function() {
var n = $("#n").val();
jQuery.ajax({
type: "GET",
url: "function.php",
data: "n=" + n,
success: function(results) {
alert(n);
}
});
});
});
SCRIPT;