如何从ajax响应结果中删除html doctype

时间:2013-02-19 06:48:50

标签: ajax salesforce visualforce

我有一个ajax函数调用一个visualforce页面。响应返回带有html doctype的结果。我只想要数据。

$(document).ready(function() {
            $.ajax({
                type: "POST",
                url: "/apex/HotStuckLeadReportAjaxPage",
                data: { name: "John", location: "Boston" }
                }).done(function( msg ) {
                    alert( "Data Saved: " + msg );
                });
       });

输出:

Data Saved: 

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


    {"sEcho":0,"iTotalRecords":"2","iTotalDisplayRecords":"2","aaData":[["8","1","sdf","test","test"],["9","12","asdf","asdf","asdf"]]}</html>

2 个答案:

答案 0 :(得分:4)

在HotStuckLeadReportAjaxPage页面中添加contentType

<apex:page  contentType="application/json">

答案 1 :(得分:0)

在你的情况下你可以

  1. 简单跳过第一行
  2. 确保您的服务器不发送它。串
  3. 用Javascript替换Exact DocType行,因为它经常 整个项目没有变化。
  4. 执行高级正则表达式 删除[但它与字符串替换相同]