Bug Tracker

Opened 13 years ago

Closed 13 years ago

#955 closed bug (worksforme)

$ajax({dataType: 'html' (but should be 'script') .... works in safari, but not ff

Reported by: stevenbristol@… Owned by:
Priority: trivial Milestone: 1.1.4
Component: ajax Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by john)

Here is my code:

function related_stories_new_page(url, page){

jq.ajax({

dataType: 'html', url: url, data: 'page=' + page, success: function(res){eval(res);}, error: function(){alert('could not retrieve the new page.');} });

return false;

}

The code should be:

function related_stories_new_page(url, page){

jq.ajax({

dataType: 'script', url: url, data: 'page=' + page, success: function(res){eval(res);}, error: function(){alert('could not retrieve the new page.');} }); return false;

}

because the call returns javascript, not html.

When the incorrect dataType is present (first function), Safari will eval the js that is returned anyways, while Firefox will do nothing.

The behavior should be consistent.

They both behave the same with the second function.

Change History (2)

comment:1 Changed 13 years ago by malsup

Are you saying that FF doesn't eval the response even though you're explicitly invoking eval yourself? I've tried to duplicate this but I can't. In the script below, FF is correctly evaling the text in may1.txt.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="jquery-1.1.2.js"></script>
<script type="text/javascript">
$(function() {
    $.ajax({
        dataType: 'html', 
        url: 'may1.txt', 
        data: 'page=1', 
        success: function(res){eval(res);}, 
        error: function(){alert('could not retrieve the new page.')}
    }); 
});
</script>
</head>
<body></body>
</html>    

comment:2 Changed 13 years ago by john

Description: modified (diff)
Milestone: 1.1.4
need: Review
Resolution: worksforme
Status: newclosed
Version: 1.11.1.3
Note: See TracTickets for help on using tickets.