SOLVED:
The problem is the security of Firefox 6.0.2. I changed my request URL from:
http://mysite.com/ajax/request
to / ajax / request and its work.
If you need to use cross domains, you need to use jsonp as your data type.
Thank you very much evildead
My JSON request to my server returns an empty response. This only happens on Firefox 6.0.2 and Safari on a Windows Vista computer.
The output is generated by a php script and has json / application headers.
This returns an empty answer:
$('#ajaxcall').click(function(){
var ts = new Date().getTime();
var urlz = $('#targeturl').val()+'/'+ts;
var dataString = $("#datazz").val();
$.ajax({
type: "POST", url: urlz, data: "data="+dataString,
success: function(data){
var obj = jQuery.parseJSON(data);
for (var i = 0; i < obj.length; i++) {
var object = obj[i];
for (property in object) {
var s = property + "=" + object[property] + "<br>";
$("#console").after(s);
}
}
}
});
});
Besides:
$( "#tags" ).autocomplete({
source: function( request, response ) {
$.post("http://mysite.com/v2/ajax/tag_suggestion/ab", {data:request.term}, function(data){
response($.map(data, function(item) {
if ($('#tagsboxvals').hasClass(item.name.split(' ').join('_'))){
return null;
} else {
return {
label: item.name,
value: item.name
}
}
}))
}, "json");
},
....
});
thanks for the help
Edit: this is what the PHP script generates:
$arr = array(
array('name'=>'pizza', 'point'=>'1'),
array('name'=>'blt', 'point'=>'1'));
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($arr);
This is a well-formed JSON document.
:
, 07 2011 23:58:42 GMT
Apache/2.2.3 (CentOS)
X-Powered-By PHP/5.1.6
, 26 1997 . 05:00:00 GMT
Cache-Control no-cache, -revalidate
Pragma
- 29
Content-Type/json
mysite.com
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv: 6.0) Gecko/20100101 Firefox/6.0
/json, text/javascript,/; = 0,01
Accept-Language en-us, en; q = 0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1, utf-8; q = 0,7, *; q = 0,7
Content-Type/x-www-form-urlencoded; = UTF-8
X-Requested- XMLHttpRequest
Referer http://mysite.com/v2/user/register
- 8
Cookie city = -; __utma = 100174657.1435105779.1308773648.1314994226.1315368765.113; __utmz = 100174657.1315368765.113.98.utmcsr = mysite.com | utmccn = () | utmcmd = | utmcct =
JSON
{name= "", = 1}
[ { name= "pizza", point = 1}]
, firefox .