বাংলায় জ্যাঙ্গো

Uncategorized

Fibonacci number in python

by , on
August 12, 2016
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

count = input("Enter range of fibonacci number: ")
first = 0
second = first+1
for i in range(count):
    if i<=1:
        next = i
    else:
        next = first + second
        first = second
        second = next
    print next

Uncategorized

Cross-Origin Request Blocked:(Solved)

by , on
August 10, 2016
The problem occurs when I tried to get/send request to other site developed in django. Actually I wanted to handle my app from other app with Json response. The error message is:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http//127.0.0.1:8000/card-active-deactive/1233459225/161-10-124/active. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Solution:
1.django-cors-headers add to django app to allow request from other url.
      https://github.com/ottoyiu/django-cors-headers/
2. Change views.py view return method:
response = JsonResponse({'Success':'true'})
response['Access-Control-Allow-Origin'] = '*'
return response
3.Js:
    $( document ).ready(function() {
        $(".cBalance").click(function() {
            var userId='161-10-124';
            var appKey="1233459225";
            var self = this;
          $.ajax({
           type      : 'GET',
           url       : 'http://127.0.0.1:8000/get-balance/'+appKey+'/'+userId,
           //crossDomain : true,
           dataType  : 'json',
           success   : function(data) {
                 if(data.Balance)
                 {
                    $('p').html('Your Balance is: '+data.Balance+' Taka');
                 }
                 else
                 {
                  alert('Error: '+data.Error);
                 }
           },
            error     : function(error)
            {
              alert('Error: Something went wrong!! Mail: [email protected]');
            },
         });
       });
});