Send a simple GET request

I want to send a server simple GET request, but since I see that .ajax sends an x-request-header with a header that my server does not understand.

$.ajax({ type: 'GET', url: 'coord-' + x + '-' + y + '-' + iname, success: function(data) { $('img').each(function(idx, item) { var img_attr = $(this).attr("src") var name = img_attr.match(/\d+-\d+\.\w+/) name = name + '?r=' + Math.random() $(this).removeAttr("src") $(this).attr("src",name) }) }, }) 

in headers ---> X-Requested-With: XMLHttpRequest
Is it possible to send a simple request without using x-request-with?

+4
source share
1 answer

It looks like you need to set the contentType parameter, something like this:

  $.ajax({ type: 'GET', url: 'coord-' + x + '-' + y + '-' + iname, contentType: 'application/json; charset=utf-8' success: function(data) {.... 

or

  beforeSend: function(xhr) { xhr.setRequestHeader("Content-type", "application/json; charset=utf-8"); }, 

Encosia has a good post about this from the .net environment.

+2
source

Source: https://habr.com/ru/post/1315095/


All Articles