Add path prefix to all AJAX requests
This will handle the case where the site was deployed under a path prefix.
This commit is contained in:
@@ -20,5 +20,5 @@ class @Calculator
|
||||
$('.help').toggleClass 'shown'
|
||||
|
||||
calculate: ->
|
||||
$.getJSON '/calculate', { equation: $('#calculator_input').val() }, (data) ->
|
||||
$.getWithPrefix '/calculate', { equation: $('#calculator_input').val() }, (data) ->
|
||||
$('#calculator_output').val(data.result)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class @Courseware
|
||||
constructor: ->
|
||||
Courseware.prefix = $("meta[name='path_prefix']").attr('content')
|
||||
new Navigation
|
||||
new Calculator
|
||||
new FeedbackForm
|
||||
|
||||
@@ -5,6 +5,6 @@ class @FeedbackForm
|
||||
subject: $('#feedback_subject').val()
|
||||
message: $('#feedback_message').val()
|
||||
url: window.location.href
|
||||
$.post '/send_feedback', data, ->
|
||||
$.postWithPrefix '/send_feedback', data, ->
|
||||
$('#feedback_div').html 'Feedback submitted. Thank you'
|
||||
,'json'
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
jQuery.postWithPrefix = (url, data, callback, type) ->
|
||||
$.post("#{Courseware.prefix}#{url}", data, callback, type)
|
||||
|
||||
jQuery.getWithPrefix = (url, data, callback, type) ->
|
||||
$.get("#{Courseware.prefix}#{url}", data, callback, type)
|
||||
|
||||
$ ->
|
||||
$.ajaxSetup
|
||||
headers : { 'X-CSRFToken': $.cookie 'csrftoken' }
|
||||
@@ -18,8 +24,8 @@ $ ->
|
||||
element.schematic.update_value()
|
||||
|
||||
schematic_value $("#schematic_#{circuit_id}").attr("value")
|
||||
$.post "/save_circuit/#{circuit_id}", schematic: schematic_value, (data) ->
|
||||
$.postWithPrefix "/save_circuit/#{circuit_id}", schematic: schematic_value, (data) ->
|
||||
alert('Saved') if data.results == 'success'
|
||||
|
||||
window.postJSON = (url, data, callback) ->
|
||||
$.post url, data, callback
|
||||
$.postWithPrefix url, data, callback
|
||||
|
||||
Reference in New Issue
Block a user