views:

65

answers:

1

Firstly, I did look at related posts, but none of them quite stoops down to my stupidity levels. Its my first time working with web technologies and I'm trying to work with Ajax/JQuery and Django. Here is the code:

$(document).ready(function() {                                                
    $('#result').ajaxError(function() {                                       
       $(this).text('Triggered ajaxError handler.');                           
    });                                                                       
    $('#b').click( function() {                                               
        codes = $('#code').text();                                            
        $.get("/questions/compile",                                           
            function(data){                                                   
                alert("data saved" + data);                                      
            });                                                                   
    });                                                                       
});       

Now this code works fine and I get a alert box as expected. But when I change $.get to $.post, I get ajaxerror. I did try using $.ajax with appropriate values, but get same problem as $.post . Firing up Firebug, shows an error at line 5252 in jquery.js. That line is

xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );

I'm not sure how to debug any further. And since I'm not sending any data, $.post should work just as well as $.get. Now go ahead and point out my stupidity. Cheers.

A: 
    $('#b').click( function() {
                    $.ajax({
                    type: "POST",
                    url: "/questions/compile",
                    data: "codes="+codes.text(),
                    success: function(data){alert("Data Saved!: "+data)}
    });});

and on the /questions/compile file, you need something like

echo $_POST['codes'];

any other questions?

Michael
I get exactly the same response. Replacing 'POST' with 'GET' in your code works just fine. But with POST, i get ajaxerror.
Neo