dongzengzai4567 2011-07-22 02:51
浏览 197
已采纳

使用JQuery从post()接收响应

I had a script working using Ajax (POST method) via plain Javascript. Now I'm trying to learn JQuery as it seems easier but I am having problem with the response of a request

$.post('ajax/wrapper.php', {'desc':$('#description').val()},
        function(data){
            $('#something').html(data);
        });

When I do that the request is successfully sent. I can see the changes on my DB but the response is not showing up in div#something. I also tried

...
   $('#something').html($(data));
...

Thanks in advance

  • 写回答

5条回答 默认 最新

  • drodsh7940 2011-07-22 06:18
    关注

    commenting out the following line worked: header("Content-type: text/xml; charset=iso-8859-1")

    See this document and the dataType parameter in jQuery.ajax. You should either return HTML with a text/html MIME type, or set the dataType parameter to 'html':

    $.ajax('ajax/wrapper.php', {
        data: {'desc':$('#description').val()},
        dataType: 'html',
        type: 'POST',
        success: function(data){
            $('#something').html(data);
        }
    }).then(console.log); // debug
    

    The first is preferable, as you really are returning HTML, and text/html is the correct MIME for that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!