[Answer]-Ajax post to local URL

1👍

Like Vaishak’s answer. You map the view in urls.py:

url(r'^postdata$', 'name_of_your_app.views.postdata')

Then you call it with jQuery like this:

$.ajax({
   type: "POST",
   url: "/postdata/",
   // ...

0👍

If you look at the browser console, you may find an exception stating that the request is prevented because of Same Origin Policy violations

If the domain from which your page is loaded is different from the domain to which the the request is made then it will not work because of Same Origin Policy restrictions.

If the server supports CORS then you can work around it.

0👍

You can do cross-domain calls if you’re posting data. You cannot load or get data from another page because of Same Origin Policy.

If you decide to do it the way you’ve described, i.e by posting to a local URL and then letting the server make the next request, then you don’t need to do anything special.
Your local URL is another page/method in your application.

map the method that needs to handle this request in your urls.py and forward the request to that.

Example:

If the urls.py entry is like below

url(r'^postdata$', 'application.views.postdatatoserver')

Then your URL on the test server would be

http://localhost:8000/postdata

Leave a comment