I have problems with this function:
开发者_高级运维<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<title>Untitled Document</title>
<script type="text/javascript">
jQuery(document).ready(function(){
$.get("http://www.boersenpoint.de/pages/charts/shareSupplier.php?request=topFlop", { indexName: "DAX" } ,function(data){
$(data).find('share').each(function(){
alert('');
});
});
});
</script>
</head>
<body>
</body>
</html>
Firebug can not find any errors. By theory 4 alerts should appear, but the don't. Why?
The problem is the same-origin policy. This means that you cannot do AJAX requests to a domain unless the page you are on is also on that domain.
The easiest way to get around it would be to set up a script on your server that proxied the requests -- you make a request to your server, the server makes the request to the other server and feeds the response back to you.
If the remote server supports it, you could also use JSONP, but I doubt that is possible as the page is an XML document.
$(function(){
$.get("http://www.boersenpoint.de/pages/charts/shareSupplier.php?request=topFlop", {indexName: "DAX"}, function(data) {
$(data).find('share').each(function(){
alert('');
});
});
});
There are a couple problems with your code...
- You are making a remote request via ajax which is explicitly prohibited by the same origin policy
- EVEN IF you weren't violating that policy, that doesn't guarantee you'd see an alert - what if
data
is empty? If so,.find('share').each
would not execute ==> no alert. - Some browsers (mostly really old ones) actually ignore the
alert();
statement if it doesn't contain text (I don't know about the empty string as you have though, just something to keep in mind).
To summarize, your specific problem in this case is the same-origin policy violation. 2. and 3. are for your benefit in future development.
精彩评论