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

131
Views
$.get how to add headers using laravel

i want to add this headers

headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
},

to my $.get jquery request

$('.wilayas').on('change', function(x) {
        /*             
                    $('.dayras').find('option')
                        .remove()
                        .end() */
        alert(this.value)

        $.get("{{ route('customer.auth.dayras') }}", {
                data: this.value
            },
            function(data, status) {
                alert(data);
                $('.dayras').append(`
             <option value="-">-</option>
        `);
                data.map(dd => {
                    $('.dayras').append(`
             <option value="${dd.id}">${dd.dayra}</option>
        `);
                })
            });
    });

am getting the html response instead of json

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The syntax of the jQuery ajax headers option :

$.ajax({ 
    headers: {          
        "Accept": "text/json"
        "Content-Type": "application/json"
    }    
    ...
    ...
});

The syntax of the jQuery ajax headers option set or overwrite with the beforeSend callback function :

$.ajax({
    url: "{{ route('customer.auth.dayras') }}",
    data: { foo: bar },
    type: "GET",
    beforeSend: function (jqXHR, settings) { 
        jqXHR.setRequestHeader("Accept", "text/json");
        jqXHR.setRequestHeader("Content-Type", "application/json");
    }
    ...
    ...
});
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!