weixin_33709609 2015-04-28 09:45 采纳率: 0%
浏览 26

在jQuery中获取解析错误

I am trying to send data to server and get back some data in json format using ajax, what i've tried

if (!empty($_REQUEST['data1'])) {
       $dt = $_REQUEST['data1'];
       $arr = [1,2,3];
       header("Content-Type: application/json", true);
       echo json_encode($arr);
 }
<script>
        jQuery(document).ready(function(){
             jQuery('.selectpicker').selectpicker();
             jQuery('#datepick').datepicker({
                    format: "dd/mm/yyyy"
             });
             jQuery('.client_list a').click(function() {
                alert(jQuery(this).text()); 
                var data={};
                data['client_name']=jQuery(this).text();
                load_data(data,window.location.pathname);
             });
         });
        var load_data=function(data,url,selector){
            jQuery.post(url,{'data1':data})
            .done(function(result){
                console.log(result+"Hello");
            })
            .fail(function( jqXHR, textStatus) {
                console.log( "failed due:"+ textStatus);
            });
        };
    </script>

I'm getting parseerror why is is this

UPDATE
my php script and jquery are in one file and my url is window.location.pathname inside getJSON

  • 写回答

2条回答 默认 最新

  • DragonWar% 2015-04-28 09:46
    关注

    When jQuery receives a JSON response from an AJAX request it will automatically deserialise it for you. The error you're seeing is because you're calling parseJSON on an object, you just need to remove that call:

    jQuery.getJSON(url,{'data1':data})
        .done(function(result){
            console.log(result + "Hello");
        })
        .fail(function( jqXHR, textStatus) {
            console.log( "failed due:"+ textStatus);
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置