Why does this call to jQuery's $.ajax() fire an empty request in Chrome and Firefox?
I am trying to call a 开发者_StackOverflow中文版WCF RESTful service from jQuery. I am using JSON to encode both request and response.
The following code functions correctly in IE8:
url = 'http://ipv4.fiddler:5683/WeatherWCF/NewBinding/MyService/GetValueFloat';
$.ajax({
url: url,
data: '{"alias": "Udetemperatur"}',
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "text", // not "json" we'll parse
success:
function(res) {
alert('Received response: ' + res);
}
});
However, in both Firefox and Chrome, res contains an empty string. After using Fiddler to monitor the request, it appears that jQuery sends an empty request to the server as shown in this screen dump: http://imgur.com/EJgwS.png
This is the successful request: http://imgur.com/S77BA.pngWhat am I doing wrong?
Kind regards,
Martin
http://ipv4.fiddler:5683
. Due to security policies cross domain ajax requests are not allowed. In FireFox use FireBug to see exactly what's sent to the server and what's the response.
First check Darin Dimitrov's answer. Then consider using dataType: "jsonp"
to make cross domain calls which return json data.
Check the jQuery.ajax documentation for more information
Try changing the name of the Url variable..
either
myurl = 'http://ipv4.fiddler:5683/WeatherWCF/NewBinding/MyService/GetValueFloat';
$.ajax({
url: myurl ,
or put quotes around the key name ..
url = 'http://ipv4.fiddler:5683/WeatherWCF/NewBinding/MyService/GetValueFloat';
$.ajax({
'url': url,
精彩评论