samedi 25 avril 2015

Cannot locate endpoint with AJAX


My AJAX cannot find the endpoint /auth/signup/ and I am not sure why. If there is anything else missing please let me know. I think I might have set my urls.py incorrectly

I get this ouput:

POST http://ift.tt/1Qvcudc 500 (INTERNAL SERVER ERROR)

JS:

function ajaxPost(endpoint, payload) {
    console.log("ajaxing");
    console.log(payload);
    $.ajax({
        url: endpoint,
        type: "POST",
        data: payload,
        success: console.log("YES!")
        });
    }
}

HTML:

<div role="tabpanel" class="tab-pane fade in" id="signup-pane">
  <form class="signup-form" method="post" action="/auth/signup/" id="create-account">
      {% csrf_token %}
      <input id="signup-firstname" type="text" placeholder="First Name">
      <input id="signup-lastname" type="text" placeholder="Last Name">
      <input id="signup-email" type="email" placeholder="Email">
      <input id="signup-password" placeholder="Password" type="password"><div id="pswd-msg"></div>
      <input id="signup-confirm-password" placeholder="Confirm Password" type="password"><div id="result"></div>
      <input type="submit" value="Create Account" class="btn btn-xl" id="create-acc-btn" name="signup-submit">
   </form>
</div>

projet urls.py

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include("index.urls")),
    url(r'auth/', include("userapp.urls"))
)

userapp urls.py

urlpatterns = patterns('',
    url(r'signup/$', register),
)

userapp views.py

def register(request):
    registered = False
    if request.method == "POST":
        post_data = request.POST.get("firstName")
        print "here!!"
        print post_data
        return render(request)

    else:
        print "there"
        return render(request)


Aucun commentaire:

Enregistrer un commentaire