Reputation: 748
Hello I'm trying to change a piece of code that I found in a google search, to do my module. The link https://www.ostraining.com/blog/joomla/search-ajax/
My code is:
My mod_ajax_handler
$js = <<<JS
(function ($) {
$(document).on('click', 'input[type=submit]', function () {
var value_0 = $('input[name=nome]').val(),
var value_1 = $('input[name=email]').val(),
var value_2 = $('input[name=contacto]').val(),
var value_3 = $('input[name=textinfo]').val(),
request = {
'option' : 'com_ajax',
'module' : 'ajax_insert',
'data_0' : value_0,
'data_1' : value_1,
'data_2' : value_2,
'data_3' : value_3,
'format' : 'raw'
};
$.ajax({
type : 'POST',
data : request,
success: function (response) {
$('.search-results').html(response);
}
});
return false;
});
})(jQuery)
JS;
And my html on the side of client
<form>
<input type="text" name="nome" />
<input type="text" name="email" />
<input type="text" name="contacto" />
<input type="text" name="textinfo" />
<input type="submit" value="Insert articles" />
</form>
<div class="search-results"></div>
I get a SyntaxError: missing variable name in the line
var value_1 = $('input[name=email]').val(),
My first concern, can I send more than one location clauses? Second Second why the error in that specific line?
Thanks in advance for the help!!!
Upvotes: 1
Views: 75
Reputation: 139
You are declaring your variables in correctly. Var is a language construct that declares the following is a variable. Either change your code to use semicolons at the end of each var statements as follows:
var value_0 = $('input[name=nome]').val();
var value_1 = $('input[name=email]').val();
or remove all but the first var statement as follows:
var value_0 = $('input[name=nome]').val(),
value_1 = $('input[name=email]').val(),
value_2 = $('input[name=contacto]').val();
Upvotes: 2