redmine - im trying to create issue from external server, but there is error "same-origin policy"« Wróć do listy pytań

custom api
Wysłane przez mrmucha
Zadane przez 12/10/2016 23:45
0

goto apache vhost or userdir config and add

1
2
3
4
5
6
7
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

thenn u can use this jquery script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
        $("#wyslij").on("click",function () 
        {
            var arr = {
                "key":"aasdfsdfads23453452345454359",
                "issue" :{
                    "project_id" : "10",
                    "subject":"jest moc"
                }
            };
 
            $.ajax({
                url: 'http://my.server/issues.json',
                type: 'POST',
                data: JSON.stringify(arr),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: false,
                success: function(msg) {
                    alert(msg);
                }
            });
            return false;
        });
        $("#wyslij").on("click",function () 
		{
            var arr = {
                "key":"aasdfsdfads23453452345454359",
                "issue" :{
                    "project_id" : "10",
                    "subject":"jest moc"
                }
            };

            $.ajax({
                url: 'http://my.server/issues.json',
                type: 'POST',
                data: JSON.stringify(arr),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: false,
                success: function(msg) {
                    alert(msg);
                }
            });
            return false;
        });

remember abut key, its on right side of http://my.redmine.server.localhost/my/account

Wysłane przez mrmucha
Odpowiedziane 12/10/2016 23:48