my view:

def aget(request):
    
    if request.is_ajax() :
       
        json_data={}
        
        json_data['messege']= 'sorry'
    
        return HttpResponse(json.dumps(json_data), 
content_type='applicaton/json')
my url:

urlpatterns = patterns('',

    url(r'^$', 'post.views.home', name='home'),
    url(r'^aget/', 'post.views.aget'),
    #url(r'^admin/', include(admin.site.urls)),
)


my templete:

<form onsubmit='return false;'> {% csrf_token %}
<!--    <label for="family_content">Enter a family name to display the 
NVTs</label>
    <input id="family_content"  /> -->
    <button id='name' onclick='apost()' >ajaxpo</button>
    <button id='name' onclick='aget()' >ajaxge</button>
</form>

<div id='out'>
    
</div>
<script src="http://code.jquery.com/jquery-1.11.2.min.js";></script>

<script type="text/javascript">

function aget(){
    
  $.ajax({  type: 'GET',
            headers :{"Access-Control-Allow-Origin": 
"http://127.0.0.1:8000/";,
            'Content-Type': 'application/json; charset=utf-8'},
            url : "http://127.0.0.1:8000/aget/";,
            dataType:'json',
            async: true,
            data: {
              csrfmiddlewaretoken : '{{csrf_token}}'
            },
          
            success:function(data){
              $('#out').html(data);
              alart(JSON.stringify(data.messege));
            }
  });
   
}
    
</script>

in chrome network:

method: option
status: 200 ok
type :aplication

in chrome console:

XMLHttpRequest cannot load 
http://127.0.0.1:8000/aget/?csrfmiddlewaretoken=4ES8c0QJnVzLCQH6dqGNmS2q8sxcetoL.
 
No 'Access-Control-Allow-Origin' header is present on the requested 
resource. Origin 'http://localhost:8000' is therefore not allowed access.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/599e8b9b-9164-4dd0-b06a-e98582b7fdd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to