开发者

jQuery: $.post not working, $.get works

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.


    $('#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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜