Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XMLHttpRequest cannot load http://myApiUrl/login. No
- 'Access-Control-Allow-Origin' header is present on the requested
- resource. Origin 'null' is therefore not allowed access.
- $.ajax({
- type: "POST",
- dataType: 'text',
- url: api,
- username: 'user',
- password: 'pass',
- crossDomain : true,
- xhrFields: {
- withCredentials: true
- }
- })
- .done(function( data ) {
- console.log("done");
- })
- .fail( function(xhr, textStatus, errorThrown) {
- alert(xhr.responseText);
- alert(textStatus);
- });
- chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
- $.ajax({
- type: "POST",
- dataType: 'jsonp',
- ...... etc ....
- <?php header('Access-Control-Allow-Origin: *'); ?>
- // The following property can be used to configure cross-origin resource sharing
- // in the HTTP nodes.
- // See https://github.com/troygoode/node-cors#configuration-options for
- // details on its contents. The following is a basic permissive set of options:
- httpNodeCors: {
- origin: "*",
- methods: "GET,PUT,POST,DELETE"
- },
- app.use(function(req, res, next) {
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- next();
- });
- <cffunction name="optionsMethod" access="remote" output="false" returntype="any" httpmethod="OPTIONS" description="Method to respond to AngularJS trial call">
- <cfheader name="Access-Control-Allow-Headers" value="Content-Type,x-requested-with,Authorization,Access-Control-Allow-Origin">
- <cfheader name="Access-Control-Allow-Methods" value="GET,OPTIONS">
- <cfheader name="Access-Control-Allow-Origin" value="*">
- <cfheader name="Access-Control-Max-Age" value="360">
- </cffunction>
- Spark.get("/someRestCallToSpark", (req, res) -> {
- res.header("Access-Control-Allow-Origin", "*"); //important, otherwise its not working
- return "some text";
- });
- Ext.Ajax.request({
- url: "http://localhost:4567/someRestCallToSpark",
- useDefaultXhrHeader: false, //important, otherwise its not working
- success: function(response, opts) {console.log("success")},
- failure: function(response, opts) {console.log("failure")}
- });
- using (DBContext db = new DBContext())
- {
- return db.Customers.Select(x => new
- {
- Name = x.Name,
- CustomerId = x.CustomerId,
- });
- }
- using (DBContext db = new DBContext())
- {
- return db.Customers.Select(x => new
- {
- Name = x.Name,
- CustomerId = x.CustomerId,
- }).ToList();
- }
- @GET
- @Path("{id}")
- public Response getEventData(@PathParam("id") String id) throws FileNotFoundException {
- InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/eventdata/" + id + ".json");
- JsonReader jsonReader = Json.createReader(inputStream);
- return Response.ok(jsonReader.readObject()).header("Access-Control-Allow-Origin", "*").build();
- }
- var yql_url = 'https://query.yahooapis.com/v1/public/yql';
- var url = 'your api url';
- $.ajax({
- 'url': yql_url,
- 'data': {
- 'q': 'SELECT * FROM json WHERE url="'+url+'"',
- 'format': 'json',
- 'jsonCompat': 'new',
- },
- 'dataType': 'jsonp',
- 'success': function(response) {
- console.log(response);
- },
- });
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="*" />
- </customHeaders>
- </httpProtocol>
- $.ajax({
- url: 'http://mysite.microsoft.sample.xyz.com/api/mycall',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- type: "POST", /* or type:"GET" or type:"PUT" */
- dataType: "json",
- data: {
- },
- success: function (result) {
- console.log(result);
- },
- error: function () {
- console.log("error");
- }
- });
- <filter>
- <filter-name>CORS</filter-name>
- <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>CORS</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --allow-file-access-from-files
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement