Ajax Post 403 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Ajax 403 Forbidden Error
of this site About Us Learn more about Stack Overflow the company django ajax post 403 Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges jquery ajax post 403 forbidden Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:
403 Forbidden Ajax Post
Sign up 403 Forbidden error when making an ajax Post request in Django framework up vote 16 down vote favorite 9 I am trying to integrate jquery into a web application I am making with Django framework. I am however having a hard time trying to make a simple ajax call to work. My template file that contains the form html and
Jquery Ajax 403 Forbidden Error
javascript to handle the ajax call looks like:
My views.py that is supposed to handle the ajax call looks like: from django.core.context_processors import csrf from django.shortcuts import render_to_response from django.template.loader import get_template from django.template import Context,RequestContext from django.views.decorators.csrf import ensure_csrf_cookie from django.http import HttpResponse # access resource def hello(request): c = {} c.update(csrf(request)) if request.is_ajax(): t = get_template('template.html') #html = t.render(Context({'result': 'hello world'})) con = RequestContext(request, {'result': 'hello world'}) return render_to_response('template.html', c, con) else: return HttpResponse('Not working!') I have tried to follow the official documentation on Cross-Site Request Forgery Protection and also looked at several stackoverflow questions addressing a similar problem. I have included the {% csrf_token %} in my html template file but it still doesn't seem to be working. I get an error in the cohere for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business ajax get 403 forbidden Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
403 Forbidden Error In Ajax Post Call
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just networkerror 403 forbidden ajax like you, helping each other. Join them; it only takes a minute: Sign up AJAX 403 forbidden when making ajax request up vote 4 down vote favorite The website initiates ajax request but always get return 403 error http://stackoverflow.com/questions/19333098/403-forbidden-error-when-making-an-ajax-post-request-in-django-framework for all browsers. I tested it by initiating the same call in firebug console, it works (status: 200) What is the problem can be deduced? jQuery.ajax({ url: "cart_ajax_get_product.php", data: {id: 355, qty: 1}, success: function(data) { }); }, error: function(err) { } }); Thanks ajax general-network-error share|improve this question edited Jan 28 '13 at 4:06 Musa 65.8k106384 asked Jan 28 '13 at 3:11 Ictuser Ai 2113 Can we get some of your code http://stackoverflow.com/questions/14554935/ajax-403-forbidden-when-making-ajax-request to help you out better. –AgnosticDev Jan 28 '13 at 3:12 403 is a permissions error, which could stem from the AJAX method expecting a post request instead of a get request from your browser. But without code or at least a link to the page that's causing the problem, we can only guess. –cliffbarnes Jan 28 '13 at 3:38 jQuery.ajax({ url: "cart_ajax_get_product.php", data: {id: 355, qty: 1}, success: function(data) { }); }, error: function(err) { } });
–Ictuser Ai Jan 28 '13 at 3:43 I asked my hosting company,,, and got reply that my website violate some restriction rule detecting for sql injection by mod_security .... it should relate to cookies, raw: "%7B%22cart%22%3A%5B%7B%22id%22%3A305%2C%22qty%22%3A1%7D%5D%7D", value: "{"cart":[{"id":305,"qty":1}]}" could anyone help for this problem ? –Ictuser Ai Jan 28 '13 at 4:58 more findings: cookie causes 403: {"cart":[{"id":411,"qty":"4"}]}, I modified it as {"cart":[{"id":411,"qty":4}]} by Firebug and refresh the page, 403 disappeared. I don't know why. –Ictuser Ai Jan 28 '13 at 6:24 | show 2 more comments 2 Answers 2 active oldest votes up vote 0 down vote Might be an issue related to apache mod_security. Try forcing the ajax request to GET instead of POST: jQuery.ajax({ type:"GET", url: "cart_ajax_get_product.php", data: {id: 355, qty: 1}, success: function(data) { }); }, error: function(err) { } }); Or
here for a quick overview of the site Help Center Detailed answers to any questions you http://stackoverflow.com/questions/11185285/ajax-jquery-call-getting-networkerror-403-forbidden-error-in-response might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or https://elgg.org/discussion/view/2015368/error-403-forbidden-when-sending-ajax-request posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community 403 forbidden of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Ajax jquery call getting NetworkError: 403 Forbidden error in response up vote 3 down vote favorite 1 I am using apache tomcat as a web server. I have deployed webservices on tomcat. If i post ajax post 403 request through jquery ajax from local file system to tomcat webservice in response i am getting 403 error. If i run the same script from the same container i am getting valid response from the webservice. I am using following code. function callservice() { jQuery.support.cors = true; var mobNo = document.getElementById('mobileNo').value; var acctNo = document.getElementById('accountNo').value; //var id = document.getElementById('id').value; var custNo = document.getElementById('customerId').value; //var mobNo = document.getElementById('txt_name').value; //alert("mobileNo" + mobNo+"accountNo" + acctNo+"customerId "+custNo); var url = "http://localhost/mobile-services/rest/user/"; var dataVal = {}; dataVal["mobileNo"] = mobNo; dataVal["accountNo"] = acctNo; dataVal["customerId"] = custNo; var forminput = JSON.stringify(dataVal); $.ajax({ url: url, type: "POST", data:forminput, processdata: true, contentType: "application/json;", beforeSend: function () { }, headers : { "Content-Type" : "application/json", "Accept" : "application/json" }, success: function (data) { if (data.authenticated==true) { window.location.replace("http://localhost:8080/mobile-services/selected_services.jsp?userId="+data.id); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { try { alert(JSON.stringify(XMLHttpRequest) + "\n" + textStatus + "\n" + errorThrown); } catch (ex) { alert("Exception occured.. "); } finally { } } }); }
sending ajax request Azartech@azar.developer 0 likeserror 403 forbidden when sending ajax requestBy Azartech 602 days ago Replies (4) Hi again.I'm developing a locations plugin for my projectI have a select box for states that lets user select a state from available options. Whenever the user makes a selection an ajax request is send to server for fetching a list of cities for a specific state. I'm using firebug for debugging ajax calls. I'm receiving 403 error and see no results.I have this snippet in my start.php file:elgg_register_ajax_view('locations/cities');and here is my snippet code for ajax request:$("#states").change(function() { stateId = $("#states").val(); $.ajax({ type: 'GET', dataType: 'html', cache: false, url: ""+'ajax/view/locations/cities?stateId='+stateId, success: function(data) { alert('Call Success'); } }); });and finally here is the content of cities.php ajax view (mod/locations/views/locations/cities.php):state_id = (int) get_input('state_id'); echo "This is a test";I studied the galliComments plugin and much of these code is similar to it, But I wonder why i am receiving this error?Replies Cim@manacim 0 likesBy Cim 602 days agoDid you forget to make default folder?mod/locations/views/default/locations/cities.php Azartech@azar.developer 0 likesBy Azartech 602 days agoThe problem was that I placed the call to elgg_register_ajax_view in page_handler function. It should be placed in init function.But there is another problem. I don't receive output from this call. The output is empty.$("#states").change(function() { stateId = $("#states").val(); $.ajax({ type: 'GET', dataType: 'html', cache: false, url: ""+'ajax/view/locations/cities?stateId='+stateId, success: function(data) { if(data.length>0){ alert(data); } } }); }); Steve Clay