Skip to main content

Bug Tracker

Side navigation

#955 closed bug (worksforme)

Opened February 13, 2007 09:07PM UTC

Closed July 20, 2007 10:03PM UTC

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

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

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.

Attachments (0)
Change History (2)

Changed May 02, 2007 12:42AM UTC by malsup comment:1

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>    

Changed July 20, 2007 10:03PM UTC by john comment:2

description: 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.\ 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. \
milestone: → 1.1.4
need: → Review
resolution: → worksforme
status: newclosed
version: 1.11.1.3