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

163
Views
get css this and value selector from jquery ajax success data

how get access to desired selector class from internal ajax success settings?

example: inside form with class 'formdataaj' are located one div with class 'img_ajx', where i want write text by ajax response.

My problem are that i can't access to selector by $(this). If i put fixed class $('.formdataaj .img_ajx').text(jsondata.image); work without problems, but obviously only in first class 'formdataaj'.

Thanks

my code:

$('.formdataaj').each(function(){
        $(this).on('submit',function(e){
        e.preventDefault();
        var form_data = new FormData(this);
        //console.log(...form_data);
        $.ajax({
            type: 'post',
            url: 'php/extra_update.php',
            data: form_data,
            processData:false,
            contentType:false,
            cache: false,
            success: function(data)
            {
                var jsondata = $.parseJSON(data);
                console.log(jsondata);
                $(this).find(".img_ajx").text(jsondata.image);
            }
        })
        
    })
    })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

// you need to asign [this keyword] to variable out of success scope 
$('.formdataaj').each(function(){
   var $this = $(this);
        $(this).on('submit',function(e){
        e.preventDefault();
        var form_data = new FormData(this);
        //console.log(...form_data);
        $.ajax({
            type: 'post',
            url: 'php/extra_update.php',
            data: form_data,
            processData:false,
            contentType:false,
            cache: false,
            success: function(data)
            {
                var jsondata = $.parseJSON(data);
                console.log(jsondata);
                $this.find(".img_ajx").text(jsondata.image);
            }
        })
        
    })
    })
about 4 years ago · Juan Pablo Isaza 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!