Is JavaScript allowed to call a remote web page during a click event?
When viewing the click in firebug, the cal开发者_如何学Pythonl turns red (i.e. error) but I can't see the error because the page redirects.
So is it allowed to call a remote website (in my case, its a 1x1 image using a standard url like http://www.example.com/becon).
You are allowed to request images form other domains without issue. Assuming you don't actually care about doing something with the image (ie you're doing data collection with the image request) do something like this:
function getImage(url) {
var tImage = new Image();
tImage.src = url;
}
$('theElementYoureInterestedIn').bind( 'click',
function() {
getImage('http://www.theImage.com/img.jpg')
}
);
Now, if you're looking to get something other than an image (HTML for instance), you'll run into XSS issues.
If I understand your question, yes.
Click events often do AJAX requests (calls to a remote web page) or appending things such as images (which can also have remote web pages).
You can do whatever you want inside the function bound to a click event. Jquery isn't doing anything special there, just binding an event handler.
It sounds like you should place the redirect on hold and inspect the call you're making. Red in firebug means a request returned something other than 200, i.e. a 404 or 500. You might also check your web server's error logs. If you're just sending a request for an image, it sounds like probably it's a 404, and you have the path to the image incorrect.
精彩评论