2014-01-21 86 views
0

我有一个页面,我想每隔一分钟刷新一次div,而不刷新整个page.Div从一个php文件中获取数据,他们在另一个xml文件中计算更大的价格。我读了最好的方法是ajax请求。ajax请求响应虚假数据

我的Ajax代码:

<script type="text/javascript"> 
$(function(){ 
var name = $("#product").val(); 
    $.ajax({ 
    type: "GET", 
    url: "maxPrice.php", 
    dataType: "text", 
    data: {'product_name' : name}, 
    error: function(XMLHttpRequest, textStatus, errorThrown) { 
    alert(textStatus); 
    }, 
    success:function(result) { 
     alert(result); 
    } 
    }); 
}); 
</script> 

php文件:

<?php 
$product_name = $_GET['product_name']; 

    $loop = 0; 
    $auction_price_db = 0; 
    $id_product = id_from_product_name($product_name); 
    $doc = new DOMDocument(); 
    $doc->load('C:/wamp/www/store/connections/auctions.xml'); 
    $xpath = new DOMXPath($doc); 

    $xml_offers = simplexml_load_file('C:/wamp/www/store/connections/offers.xml'); 
    $xml_auctions = simplexml_load_file('C:/wamp/www/store/connections/auctions.xml'); 

    foreach ($xml_auctions->auction as $auction){ 
     if ($auction->auction_id == $id_product) { 
      $auction_price_db = (string)$auction->start_price; 
      $item = $loop; 
      break; 
     } 
     $loop++; 
    } 

     foreach ($xml_offers->offer as $offer){ 
     if ($offer->id_product == $id_product) { 
      $user_offer = (string)$offer->price; 
      if ($user_offer > $auction_price_db) { 
       $parent = $doc->getElementsByTagName('auction')->item($item); 
       $query = $xpath->query('start_price',$parent); 
       $query->item(0)->nodeValue = $user_offer; 
       $doc->save('C:/wamp/www/store/connections/auctions.xml'); 
       $xml_products = simplexml_load_file('C:/wamp/www/store/connections/products.xml'); 
       foreach ($xml_products->product as $product){ 
         if ($id_product == $product->product_id) { 
          $product->price = $user_offer; 
          $xml_products->asXML('connections/products.xml'); 
         } 
       } 
       $response = "{\"user_offer\":\"".$user_offer."\"}"; 
      } 
     } 
    } 
echo <<<HERE_DOC 
$response 
HERE_DOC; 

?> 

在阿贾克斯的成功,我有一个警惕,如果从阿贾克斯的数据与此right.But它的响应。 。

<br /> 
<font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'> 
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>(!)</span> Fatal error: Call to undefined function id_from_product_name() in C:\wamp\www\store\maxPrice.php on line <i>6</i></th></tr> 
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> 
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> 
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>692568</td><td bgcolor='#eeeeec'>{main}()</td><td title='C:\wamp\www\store\maxPrice.php' bgcolor='#eeeeec'>..\maxPrice.php<b>:</b>0</td></tr> 
</table></font> 

为什么我得到这个反应呢?如果我尝试删除maxPrice所有代码和回声只有$ PRODUCT_NAME,我在ajax请求中传递它我得到正确的数据。

+3

'未定义功能id_from_product_name()在C:\ WAMP \ WWW \店\ maxPrice.php上线6'似乎成为问题,所以'$ id_product = id_from_product_name($ product_name);'正在轰炸 – MonkeyZeus

+1

有一个错误,你正在发送回调用堆栈。错误是在那里“致命的错误:调用未定义的函数id_from_product_name()在C:\ wamp \ www \ store \ maxPrice.php在线..” – Gjohn

+0

为什么?我知道这个函数工作正常.id_from_product_name是一个另一个PHP文件。我必须把它放在相同的? – user3071235

回答

0

这是来自服务器的Xdebug格式错误。如果您在第3行仔细观察,你就会从服务器上看到此错误消息:

Fatal error: Call to undefined function id_from_product_name() in C:\wamp\www\store\maxPrice.php on line 6