Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
Error sending ajax request

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!!!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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();
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!