Bug Tracker

Ticket #4734: ajax_jsonp_test.htm

File ajax_jsonp_test.htm, 1.5 KB (added by tidalwav1, 11 years ago)
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3<head>
4  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
5  <title>$.ajax test</title>
6</head>
7<body>
8  <div id="twitter_text">Fetching latest Twitter status...</div>
9<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
10<script>
11
12$(document).ready(function(){
13  $.ajax({
14
15    //The following "url" is valid, a "control" test.
16
17    url : "http://twitter.com/status/user_timeline/twitter.json?count=10&callback=?",
18   
19    //The next "url" commented out below correctly triggers the error event, since it's completely invalid.
20
21    //url : "___",
22   
23    //The next two "url"s commented out below SHOULD trigger the error event, but don't; execution just stops instead, which isn't the desired behavior.
24   
25    //url : "http://twi___tter.com/user_timeline/twiter.json?count=10&callback=?",
26    //url : "http://twitter.com/status/user_timeline/twi___tter.json?count=10&callback=?",
27
28    dataType : 'jsonp',
29    data : {},
30    success : function(data) {
31      //Do stuff with the data
32      $.each(data, function(i, item) {
33        //console.log(item);
34        $('#twitter_text').append('<br />');       
35        $('#twitter_text').append(item.text);
36      });
37    },
38    error: function(ajaxobj, txt, exceptobj) {
39      //console.log(ajaxobj, txt, exceptobj);
40      alert("AJAX Error triggered!");
41    }
42  });
43
44});
45
46</script>
47
48</body>
49</html>