Send a simple GET request

人走茶凉 提交于 2019-12-07 12:31:43

问题


I want to send a server simple GET request but as I see the .ajax sends x-requested-with header which my server doesn't 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?


回答1:


This 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 enviroment.



来源:https://stackoverflow.com/questions/3205401/send-a-simple-get-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!