发送一个简单的GET请求简单、GET

2023-09-10 17:44:42 作者:亡命

我想送一台服务器简单的GET请求,但我看到了阿贾克斯发出的X要求,与标头,我的服务器不理解。

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)
                        })
                    }, 
                    })

在头---> X-要求,通过:XMLHtt prequest 是否有可能发出一个简单的请求,而无需使用的X请求呢?

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

推荐答案

这看起来像你需要设置的contentType参数,是这样的:

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) {....

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

Encosia 已经从.NET环境这个好岗。

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