Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

This code fetches the HTML source of http://www.foo-example-site.com/(index.html)

$.ajax({ url: 'http://www.foo-example-site.com', success: function(data) {
    alert(data); 
    } 
}); 

However, the website changes the content of HTML source depending on User Agent.
If I want to switch User Agent to this below only when using ajax request, how can I fix my code?

Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16
share|improve this question

marked as duplicate by Diodeus, Ktash, EricLaw, undefined, TravisO 13 hours ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 2 down vote accepted

No, this is part of the HTTP protocol. You can change it in the browser, but not in an AJAX call.

share|improve this answer
Thanks. Is there any trick to let user's browser to grab external HTML source with customized User Agent params? – cat 13 hours ago
You need to write a browser plug-in to do that. – Diodeus 13 hours ago
It seems too much work:( what if I use PHP or RUBY? Is it feasible? – cat 13 hours ago
1  
You can do that using CURL on the server, but not on the browser. – Diodeus 13 hours ago
Thanks very much:) – cat 13 hours ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.