衫裤跑路 2013-05-10 09:06 采纳率: 50%
浏览 47

加载ajax JSON失败

the bellow scripts runs at my Local Host but does not work at my Site. I'm just testing simple Json script in jqueryMobile list format any idea what is wrong??

thanks

HTML page click to call Ajax function:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> 
    <link rel="stylesheet" href="protected/jQuery/jquery.mobile.structure-1.0.1.min.css" />
    <link rel="stylesheet" href="protected/themes/Green/red_theme.min.css" />
<script src="news_services/js/jquery.js"></script>
<script src="news_services/js/jquery.mobile-1.0rc1.min.js"></script>
<script type="text/javascript" src="protected/jsnM.js"> </script>
</head>
<body >
<div data-role="page" id="home" >
    <div data-role="header" >
        <h1>JSON testing</h1>
        <div data-role="controlgroup" data-type="horizontal"></div>
    </div>
    <div data-role="content">
        <p> Json testing</p>
    </div>
    <div data-role="footer">
        <a href="#getAll_JSON" onClick="jsn1()" data-role="button" data-inline="true" data-icon="info">call JSON</a>
    </div>
</div>
<div data-role="page" id="getAll_JSON">
    <div data-role="header" data-position="fixed" >
        <h1>Json format</h1>
        <div data-type="horizontal" >
            <a href="#home" data-role="button"  data-inline="true" data-icon="home">Home</a>
        </div>
    </div>
    <div data-role="content">
        <ul id="sitesList" data-role="listview" data-filter="true" data-split-icon="gear" >
        </ul>
    </div>
    <div data-role="footer" data-position="fixed"></div>
</div>
<div id="detailsPage" data-role="page" >
    <div data-role="header">
        <h1>info</h1>
        <div data-type="horizontal" >
            <a href="#home" data-role="button"  data-inline="true" data-icon="home">Home</a>
        </div>
    </div>
    <div data-role="content">
        <div id="sitesDetail" >
        </div>
    </div>
</div>
</body>
</html>

call Ajax here:

var areaID=0;

function jsn1(val)
{   
var url_Category="http://gonorth.co.il/protected/indexJSON.php?";

$.ajax({
    url: url_Category,
    type: "GET",
    data: 'No='+val+"&area="+areaID,
    dataType: "json",
    cache: false, 
    error: function () {
        alert('loading Ajax failure');
        } ,
    onFailure: function () {
        alert('Ajax Failure');
    } ,
     statusCode: {
        404: function() {
            alert("missing info");
        }   
    },
    success: function(result) {
            $('#sitesList li').remove();
        $.each(result.sites,function(index,dat){
            $("#sitesList").append(
                '<li>'+
                '<img src="images/'+dat.coupon_img+'" width=80/>' +
                '<p >Name: '+dat.coupon_name+'</p>'+
                '<p >info: '+dat.street+'</p>'+
                '<p >address:'+dat.coupon_tmp+'</p>'+
                '</li>'
            );
        });

        $('#sitesList').listview('refresh');        
    }
});
}

PHP results:

<?php
    $arr = array();
        $arr[] =[
                "coupon_id" => '1',
                "coupon_img" => '1.jpg',
                "street" => 'long text', 
                "coupon_tmp" => 'Address', 
                "coupon_name" => 'Name'
                ];
echo '{"sites":'.json_encode($arr).'}';
?>
  • 写回答

3条回答 默认 最新

  • weixin_33722405 2013-05-10 09:19
    关注

    When I visit this link: http://gonorth.co.il/protected/indexJSON.php, it looks like your JSON is being served through a PHP parser by your web server. You should look into your web server's settings and find out how to set it up in such a way that JSON files will be served with a content-type of application/json. The current response comes down with a conten-type of text/html, which is most likely because it's trying to be parsed by a PHP parser and the parser chokes on the syntax, or something like that, and the server then renders a html error page.

    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?