Page 3 of 3
Re: How do you submit more than one variable via Ajax?
Posted: Wed Jun 29, 2016 10:25 am
by simonmlewis
Code: Select all
$.ajax({ url: '/ajax-search.php',
data: {action: 'test'},
type: 'GET',
success: function(output) {
alert(output);
}
});
Something like this, but not sure how or where. OR how it compiles those two values.
Re: How do you submit more than one variable via Ajax?
Posted: Wed Jun 29, 2016 10:26 am
by Celauran
simonmlewis wrote:Sure. But what is the "line of code" I had to pop in, and where.... so I can see if it works this end?
Not sure what line of code you're looking for. If you go back to the original jQuery with the AJAX call in it, where does that leave things?
Re: How do you submit more than one variable via Ajax?
Posted: Wed Jun 29, 2016 11:15 am
by simonmlewis
I'm sorry I cannot see it.
Re: How do you submit more than one variable via Ajax?
Posted: Wed Jun 29, 2016 11:19 am
by simonmlewis
Like this?
Code: Select all
<script>
// This really belongs in a separate JS file, not embedded alongside PHP or HTML
$(document).ready(function() {
$('.home-search-input input').on('keyup', function(event) {
var search_string = $(this).val();
// Don't fire on very short strings
if (search_string.length > 2) {
var category = $('.home-search-cat select').val();
$.ajax({
url: '/ajax-search.php?search=' + search_string + '&category=' + category,
method: 'GET'
}).done(function(response) {
$('#txtHint').html(response);
});
}
});
$('.home-search-cat select').change(function(event) {
var category = $(this).val();
var search_string = $('.home-search-input input').val();
$.ajax({
url: '/ajax-search.php?search=' + search_string + '&category=' + category,
method: 'GET'
}).done(function(response) {
$('#txtHint').html(response);
});
});
});
</script>
Re: How do you submit more than one variable via Ajax?
Posted: Wed Jun 29, 2016 11:19 am
by Celauran
What can't you see?
What does your code look like now and what specifically is not working?