ajax php函数调用只能第一次调用

时间:2012-12-27 19:33:47

标签: php javascript ajax

我有以下函数调用一个PHP文件,该函数以Json格式返回我得到的结果,并在Javascript值中分配,如下所示。 PHP功能完全正常工作和检查。结果发送并保存在变量中,直到我从update_tipster函数更改市场变量。

我有8个标签,可以将数据发送到函数update_tipster。一旦我按下市场1空白的前4个选项卡,一切都很好。当我按下其他4个标签时,我得不到ajax的响应,我得到白页。当我尝试并将market1加载为'gh_',这是其他4-7个标签的值时,所有内容再次适用于标签5-8但是0-3为空白。

<ul>
    <li><a href="#tabs-0" onclick="update_tipster( '0', '', market_id, date_today)">
            <img src="betfair/img/horse-icon-small.png" style="vertical-align:middle">
                    <span style="padding-left:5px;">ALL PLANS</span>
        </a>
    </li>
    <li><a href="#tabs-1" onclick="update_tipster( '1', '', market_id, date_today )" >
            <img src="betfair/img/horse-icon-small.png" style="vertical-align:middle">
                    <span style="padding-left:5px;">MASTER</span>
        </a>
    </li>
    <li><a href="#tabs-2" onclick="update_tipster( '2', '', market_id, date_today )" >
            <img src="betfair/img/horse-icon-small.png" style="vertical-align:middle">
                    <span style="padding-left:6px;">PHANTOM</span>
        </a>
    </li>
    <li><a href="#tabs-3" onclick="update_tipster( '3', '', market_id, date_today )" >
            <img src="betfair/img/horse-icon-small.png" style="vertical-align:middle">
                    <span style="padding-left:6px;">LAY LOSERS</span>
        </a>
    </li>
    <li><a href="#tabs-4" onclick="update_tipster( '4', 'gh_', market_id, date_today )" >
            <img src="betfair/img/dog-icon-orange-small.png" style="vertical-align:middle">
                    <span style="padding-left:6px;">ALL PLANS</span>
        </a>
    </li>
    <li><a href="#tabs-5" onclick="update_tipster( '5', 'gh_', market_id, date_today )" >
            <img src="betfair/img/dog-icon-orange-small.png" style="vertical-align:middle">
                    <span style="padding-left:6px;">MASTER</span>
        </a>
    </li>
    <li><a href="#tabs-7" onclick="update_tipster( '7', 'gh_', market_id, date_today )" >
            <img src="betfair/img/dog-icon-orange-small.png" style="vertical-align:middle">
                    <span style="padding-left:6px;">PHANTOM</span>
        </a>
    </li>
    <li><a href="#tabs-6" onclick="update_tipster( '6', 'gh_', market_id, date_today )" >
            <img src="betfair/img/dog-icon-orange-small.png" style="vertical-align:middle">
                    <span style="padding-left:6px;">LAY LOSERS</span>
        </a>
    </li>
</ul>

使用Javascript:

Function run_ajax(market, market_id1, tipster_id1, date_today1) {
market_type=market;

if(market_id1 === '0')
    {

    $.ajax({
              type: 'POST', 
              url: "betfair/market_blank_datetime.php",
              data: "market_type="+market,
              cache: false,
              async: false,
              dataType: 'json',
              success: function(data1){
                date_today=data1.date_today;
                startTime_time=data1.startTime_time;
                market_id=data1.market_id_time;
              }
        });
    }
}

function update_tipster(tipster1, market1, market_id1, date_today1){
    tipster_id = tipster1;

    if(market_type != market1)
    {   
        market_type = market1;
        market_id='0';
    }
        runscript_menu();
        run_ajax(market_type, market_id, tipster_id, date_today1);
}

2 个答案:

答案 0 :(得分:0)

market_id1中未使用

update_tipster(),您是否忘记连续字符串?

答案 1 :(得分:0)

我修复了它,我使用了Jquery.ajax而不是$ .ajax,现在工作得很好。谢谢你的时间