Possible Duplicate:
cross-origin ‘Authorization’-header with jquery.ajax()
JQuery
I am using http://code.jquery.com/jquery-1.7.2.min.js
If i type ->http://pol638_047fe0/JSON.HTML?FN=GetPages&PIN=7659 in a browser i receive a file with my json content
Javascript
var url = 'http://pol638_047fe0/JSON.HTML';
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
username: 'ADMIN',
password: '1234',
data: {
'FN': 'GetPages',
'PIN': '7659'
},
xhrFields: {
withCredentials: true
},
sucess: function(data) {
alert('done');
console.log('data', data);
}
});
Chrome Developer Tool
Console output: Origin null error
XMLHttpRequest cannot load http://pol638_047fe0/JSON.HTML?FN=GetPages&PIN=7659. Origin null is not allowed by Access-Control-Allow-Origin.
This doesn't really bother me, because the server shouldn't care who accesses the data with the correct username and password.
Network Header:
Request URL:http://pol638_047fe0/JSON.HTML?FN=GetPages&PIN=7659
Request Headersview source
Accept: '*/*'
Cache-Control: max-age=0
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Query String Parametersview URL encoded
FN: GetPages
PIN: 7659
Ok. Something definitly went wrong here..
Now the strange thing is if i add this ajax call to the code:
...
$.ajax({
url : url,
data: {
'FN' : 'GetPages',
'PIN' : '7659'
}
});
I receive another JSON.HTML File under Network with the correct response:
Request URL: http://pol638_047fe0/JSON.HTML?FN=GetPages&PIN=7659
Request Method: GET
Status Code: 200 OK
Request Headersview source
Accept: application/json, text/javascript, '*/*'; q=0.01
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Authorization: Basic QURNSU46U0JUQWRtaW4h
Cache-Control: max-age=0
Connection: keep-alive
Host: pol638_047fe0
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Query String Parametersview URL encoded
FN: GetPages
PIN: 7659
Response Headersview source
Connection: close
Content-Type: application/octet-stream
Server: Keil-EWEB/2.1
Response:
[{"pg":0,"descr":"PC1"},{"pg":1,"descr":"PC2"},{"pg":2,"descr":"PC3"},{"pg":3,"descr":"HG1"},{"pg":4,"descr":"HG2"},{"pg":5,"descr":"HG3"},{"pg":6,"descr":"HG4"},{"pg":7,"descr":"DW1"},{"pg":8,"descr":"DW2"},{"pg":9,"descr":"CMN"}]
I have run out of ideas and i am thankful for any help, or suggestions!
Tryouts
Changing the type to jsonp helps me receive a response but doesnt help much because i get a Uncaught SyntaxError: Unexpected token ILLEGAL Error. I asume that is because the response is not jsonp formated. Is there any way i can get the json response?
Changing Access Headers on Server. I don't have the rights to do that.