weixin_33728708 2016-01-06 05:21 采纳率: 0%
浏览 3

将ajax转换为json

This is normal form submission to codeigniter framework. This is a ajax form submission. How to convert this to jason and send to below URL?

data: 'question=' + question + '&idquestion_table=' + idquestion_table + '&answer_1=' + answer_1 + '&answer_2=' + answer_2 + '&answer_3=' + answer_3 + '&answer_4=' + answer_4 + '&correct_answer=' + correct_answer + '&category=' + category,
                                url: "<?php echo base_url('index.php/admin_question_controller'); ?>",
                                type: 'put',
  • 写回答

1条回答 默认 最新

  • weixin_33670713 2016-01-06 05:31
    关注

    Hopefully my code can help you to deal with your issue

    <html>
        <input type="button" value="button" id="ID1" />
    </html>
    <script>
         $("#ID1").click(function () {
                var user = {
                    username:'***@gmail.com',
                    password:'!aA1234'
                };
            $.ajax({
                type: 'POST',
                url: 'http://***/index.php',          
                data: user,          
                datatype: "json",
                error: function (XMLHttpRequest, textStatus, errorThrown) {  
                    alert(textStatus);
                },
                success: function (data) {
                 alert(data)
                }
            });
        });
    </script>
    
    评论

报告相同问题?