1

I am trying to send some JSON data to the server but I keep getting a 415 error: Unsupported Media Type. This is my ajax call

 $.ajax({
                type: "POST",
                url: 'http://mywebsite.com?'+"token="+token+"&account="+account+"&version=1.0&method=put",
                dataType: 'jsonp',
                contentType: "text/json",
                processData: false,data: JSON.stringify(jsonData),
                success: function () {  
                    alert("Thanks!"); 
                }
            })

        }

I noticed that in the request header there is no content-type listed. So how do I set the content type for the request header?

Thanks!

4

2 回答 2

-1

我认为您的网址已损坏,您错过了/并且?

url: 'http://www.mywebsite.com/?'+"token="+token+"&account="+account+"&version=1.0&method=put",

此外,您不应使用全局 url(带有 http),因为它们被浏览器阻止...

url: "?token="+token+"&account="+account+"&version=1.0&method=put",
于 2013-09-05T20:08:53.057 回答
-1

您不能以这种方式在 url 之外发布数据。试试下面的代码

 $.getJSON("http://www.yourwebsite.com/PersonCount.aspx?id=" + id + "&dt=" + dt + "&t=" + time + "&callback=?", function(data) {
      ///  Your response from {data}
    });
于 2013-09-05T20:14:39.620 回答