I know this question was asked many times, but after reading the answers, and trying some solutions, my code still doesn't work.
Here are my working files :
my_app
-index.html
-task1
-index.html
In my_app/index.html, I declare an array , that I have to send to task1/index.html
testArray =[1, 2, 3];
var myUrl= "task1/index.html";
$.ajax({
type: "POST",
url: myUrl,
dataType: "json",
data: JSON.stringify({images:testArray}),
success: function (data) {
console.log('success');
alert(data);
}
});
window.open(myUrl);
//this code is called when a radio button is checked
The new window which points to the right url opens, but the testArray isn't sent.
I got 2 errors:
1/ Origin null is not allowed by Access-Control-Allow-Origin.
2/the variable images is not defined when I try to access it from task1/index.html
For the 1st error, I read that this may be caused by Google Chrome's restriction when it comes to use Ajax with local resources.
As suggested here Origin null is not allowed by Access-Control-Allow-Origin, I added
--allow-file-access-from-files
in Google Chrome properties. But the path was not accepted (I had a pop-up window "path not correct").
What is weird is that I tried to run the code with FireFox, I still have error 2
Is anything missing in my Post Ajax request? Is it possible to use Ajax to send data between 2 html files ?(I don't have any client/server side app here)
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…