Quick guess, you are visiting the site in your browser using http://localhost:8000. I'm betting if you instead visited it using http://127.0.0.1:8000, the AJAX query would work fine.
You have http://127.0.0.1:8000 hard coded (or being generated) everywhere. Either change your JavaScript to use localhost, only visit the site using the IP rather than the name, or better yet, try to eliminate any reference to the domain or the IP in your JavaScript by using relative URL's. -James On Jan 19, 2015 4:33 AM, "Aussie Niki" <aussien...@gmail.com> wrote: > 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 > <https://groups.google.com/d/msgid/django-users/599e8b9b-9164-4dd0-b06a-e98582b7fdd3%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CA%2Be%2BciVw66mVei2O40cXQ%2BadXg9iiuo7i6AZS%3DV2nBnZVOhCRg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.