How can I load cross domain html page with jQuery AJAX?
up vote
4
down vote
favorite
How can I load cross domain HTML page with jQuery AJAX?
Suppose I want to get a page outside my domain using jQuery AJAX:
$.get('http://www.domain.com/mypage.html', function(data) {
alert(data);
});
I will probably get this error message:
XMLHttpRequest cannot load http://www.domain.com/path/filename. Origin
null is not allowed by Access-Control-Allow-Origin.
we can't load cross domain page using AJAX because of the Same-origin policy.
I could try using 'jsonp' to bypass this restriction:
$.ajax({
type: "GET",
url: url,
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
But what if 'jsonp' is not supported in this site? this could be a problem.
What if I just want to read an external page and parse its HTML?
jquery ajax jquery-plugins cross-browser cross-domain
add a comment |
up vote
4
down vote
favorite
How can I load cross domain HTML page with jQuery AJAX?
Suppose I want to get a page outside my domain using jQuery AJAX:
$.get('http://www.domain.com/mypage.html', function(data) {
alert(data);
});
I will probably get this error message:
XMLHttpRequest cannot load http://www.domain.com/path/filename. Origin
null is not allowed by Access-Control-Allow-Origin.
we can't load cross domain page using AJAX because of the Same-origin policy.
I could try using 'jsonp' to bypass this restriction:
$.ajax({
type: "GET",
url: url,
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
But what if 'jsonp' is not supported in this site? this could be a problem.
What if I just want to read an external page and parse its HTML?
jquery ajax jquery-plugins cross-browser cross-domain
Do you have control over the "outside" domain? I ask because if so, look into CORS en.wikipedia.org/wiki/Cross-origin_resource_sharing
– JeremyWeir
Sep 7 '14 at 5:23
Related: stackoverflow.com/a/17299796/612253
– Highly Irregular
Feb 4 '15 at 3:39
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
How can I load cross domain HTML page with jQuery AJAX?
Suppose I want to get a page outside my domain using jQuery AJAX:
$.get('http://www.domain.com/mypage.html', function(data) {
alert(data);
});
I will probably get this error message:
XMLHttpRequest cannot load http://www.domain.com/path/filename. Origin
null is not allowed by Access-Control-Allow-Origin.
we can't load cross domain page using AJAX because of the Same-origin policy.
I could try using 'jsonp' to bypass this restriction:
$.ajax({
type: "GET",
url: url,
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
But what if 'jsonp' is not supported in this site? this could be a problem.
What if I just want to read an external page and parse its HTML?
jquery ajax jquery-plugins cross-browser cross-domain
How can I load cross domain HTML page with jQuery AJAX?
Suppose I want to get a page outside my domain using jQuery AJAX:
$.get('http://www.domain.com/mypage.html', function(data) {
alert(data);
});
I will probably get this error message:
XMLHttpRequest cannot load http://www.domain.com/path/filename. Origin
null is not allowed by Access-Control-Allow-Origin.
we can't load cross domain page using AJAX because of the Same-origin policy.
I could try using 'jsonp' to bypass this restriction:
$.ajax({
type: "GET",
url: url,
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
But what if 'jsonp' is not supported in this site? this could be a problem.
What if I just want to read an external page and parse its HTML?
jquery ajax jquery-plugins cross-browser cross-domain
jquery ajax jquery-plugins cross-browser cross-domain
asked Sep 7 '14 at 5:16
Ninioe
430156
430156
Do you have control over the "outside" domain? I ask because if so, look into CORS en.wikipedia.org/wiki/Cross-origin_resource_sharing
– JeremyWeir
Sep 7 '14 at 5:23
Related: stackoverflow.com/a/17299796/612253
– Highly Irregular
Feb 4 '15 at 3:39
add a comment |
Do you have control over the "outside" domain? I ask because if so, look into CORS en.wikipedia.org/wiki/Cross-origin_resource_sharing
– JeremyWeir
Sep 7 '14 at 5:23
Related: stackoverflow.com/a/17299796/612253
– Highly Irregular
Feb 4 '15 at 3:39
Do you have control over the "outside" domain? I ask because if so, look into CORS en.wikipedia.org/wiki/Cross-origin_resource_sharing
– JeremyWeir
Sep 7 '14 at 5:23
Do you have control over the "outside" domain? I ask because if so, look into CORS en.wikipedia.org/wiki/Cross-origin_resource_sharing
– JeremyWeir
Sep 7 '14 at 5:23
Related: stackoverflow.com/a/17299796/612253
– Highly Irregular
Feb 4 '15 at 3:39
Related: stackoverflow.com/a/17299796/612253
– Highly Irregular
Feb 4 '15 at 3:39
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I know this is an old post. But, I hope this will help someone else who is looking for the same.
Simply you can't. - same-origin policy or you need to set CORS headers for www.domain.com
But, If you just want to fetch an external page content to your page, there is a workaround you could do:
Create an endpoint in your server to return the HTML content for the given external URL. (because you can't get external content to the browser - same-origin policy)
JS:
var encodedUrl = encodeURIComponent('http://www.domain.com/mypage.html');
$.get('http://www.yourdomain.com/getcontent?url=' + encodedUrl, function(data) {
console.log(data);
});
Easiest way to read from a URL into a string in .NET - may use this to create /getcontent
endpoint
add a comment |
up vote
-3
down vote
You can use 'AJAX Cross Origin' a jQuery plugin to load cross domain HTML page.
AJAX Cross Origin is a jQuery plugin to allow Cross Origin AJAX requests.
With this plugin we can easily bypass the Same-origin policy and do cross domain requests.
It is very simple to use:
$.ajax({
crossOrigin: true,
url: url,
success: function(data) {
console.log(data);
}
});
You can read more about it here: http://www.ajax-cross-origin.com/
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25707287%2fhow-can-i-load-cross-domain-html-page-with-jquery-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I know this is an old post. But, I hope this will help someone else who is looking for the same.
Simply you can't. - same-origin policy or you need to set CORS headers for www.domain.com
But, If you just want to fetch an external page content to your page, there is a workaround you could do:
Create an endpoint in your server to return the HTML content for the given external URL. (because you can't get external content to the browser - same-origin policy)
JS:
var encodedUrl = encodeURIComponent('http://www.domain.com/mypage.html');
$.get('http://www.yourdomain.com/getcontent?url=' + encodedUrl, function(data) {
console.log(data);
});
Easiest way to read from a URL into a string in .NET - may use this to create /getcontent
endpoint
add a comment |
up vote
0
down vote
I know this is an old post. But, I hope this will help someone else who is looking for the same.
Simply you can't. - same-origin policy or you need to set CORS headers for www.domain.com
But, If you just want to fetch an external page content to your page, there is a workaround you could do:
Create an endpoint in your server to return the HTML content for the given external URL. (because you can't get external content to the browser - same-origin policy)
JS:
var encodedUrl = encodeURIComponent('http://www.domain.com/mypage.html');
$.get('http://www.yourdomain.com/getcontent?url=' + encodedUrl, function(data) {
console.log(data);
});
Easiest way to read from a URL into a string in .NET - may use this to create /getcontent
endpoint
add a comment |
up vote
0
down vote
up vote
0
down vote
I know this is an old post. But, I hope this will help someone else who is looking for the same.
Simply you can't. - same-origin policy or you need to set CORS headers for www.domain.com
But, If you just want to fetch an external page content to your page, there is a workaround you could do:
Create an endpoint in your server to return the HTML content for the given external URL. (because you can't get external content to the browser - same-origin policy)
JS:
var encodedUrl = encodeURIComponent('http://www.domain.com/mypage.html');
$.get('http://www.yourdomain.com/getcontent?url=' + encodedUrl, function(data) {
console.log(data);
});
Easiest way to read from a URL into a string in .NET - may use this to create /getcontent
endpoint
I know this is an old post. But, I hope this will help someone else who is looking for the same.
Simply you can't. - same-origin policy or you need to set CORS headers for www.domain.com
But, If you just want to fetch an external page content to your page, there is a workaround you could do:
Create an endpoint in your server to return the HTML content for the given external URL. (because you can't get external content to the browser - same-origin policy)
JS:
var encodedUrl = encodeURIComponent('http://www.domain.com/mypage.html');
$.get('http://www.yourdomain.com/getcontent?url=' + encodedUrl, function(data) {
console.log(data);
});
Easiest way to read from a URL into a string in .NET - may use this to create /getcontent
endpoint
edited May 23 '17 at 12:34
Community♦
11
11
answered Jul 13 '16 at 17:52
Safeer Hussain
83411222
83411222
add a comment |
add a comment |
up vote
-3
down vote
You can use 'AJAX Cross Origin' a jQuery plugin to load cross domain HTML page.
AJAX Cross Origin is a jQuery plugin to allow Cross Origin AJAX requests.
With this plugin we can easily bypass the Same-origin policy and do cross domain requests.
It is very simple to use:
$.ajax({
crossOrigin: true,
url: url,
success: function(data) {
console.log(data);
}
});
You can read more about it here: http://www.ajax-cross-origin.com/
add a comment |
up vote
-3
down vote
You can use 'AJAX Cross Origin' a jQuery plugin to load cross domain HTML page.
AJAX Cross Origin is a jQuery plugin to allow Cross Origin AJAX requests.
With this plugin we can easily bypass the Same-origin policy and do cross domain requests.
It is very simple to use:
$.ajax({
crossOrigin: true,
url: url,
success: function(data) {
console.log(data);
}
});
You can read more about it here: http://www.ajax-cross-origin.com/
add a comment |
up vote
-3
down vote
up vote
-3
down vote
You can use 'AJAX Cross Origin' a jQuery plugin to load cross domain HTML page.
AJAX Cross Origin is a jQuery plugin to allow Cross Origin AJAX requests.
With this plugin we can easily bypass the Same-origin policy and do cross domain requests.
It is very simple to use:
$.ajax({
crossOrigin: true,
url: url,
success: function(data) {
console.log(data);
}
});
You can read more about it here: http://www.ajax-cross-origin.com/
You can use 'AJAX Cross Origin' a jQuery plugin to load cross domain HTML page.
AJAX Cross Origin is a jQuery plugin to allow Cross Origin AJAX requests.
With this plugin we can easily bypass the Same-origin policy and do cross domain requests.
It is very simple to use:
$.ajax({
crossOrigin: true,
url: url,
success: function(data) {
console.log(data);
}
});
You can read more about it here: http://www.ajax-cross-origin.com/
answered Sep 7 '14 at 5:16
Ninioe
430156
430156
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25707287%2fhow-can-i-load-cross-domain-html-page-with-jquery-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have control over the "outside" domain? I ask because if so, look into CORS en.wikipedia.org/wiki/Cross-origin_resource_sharing
– JeremyWeir
Sep 7 '14 at 5:23
Related: stackoverflow.com/a/17299796/612253
– Highly Irregular
Feb 4 '15 at 3:39