2014-02-05 89 views
0

有一个网站有某种数据。网站通过来自您网页的Ajax请求发送此数据。所谓的连续加载页面。我可以使用php登录这个网站。但我无法从php下载这些额外的页面。如何将ajax代码转换为php

$(window).scroll(function() { 
    scroll = $(document).scrollTop() + window_height; 
    if (scroll > 1500){ 
      button.fadeIn(); 
     } else { 
      button.fadeOut(); 
     } 

    if(!is_load || !brend) return false; 
    document_height = $(document).height(); 

    if(document_height - scroll < 1000 && document_height != document_height_prev){ 
    p = p + 1; 
    document_height_prev = document_height; 
    var data_send = { 
     mode: 'json', 
     brend: brend, 
     p: p 
    }; 

    $.ajax({ 
     url: '/catalog/getObjectsListBrend/', 
     data: data_send, 
     type: 'post', 
       dataType: 'html', 
       success: function(data) { 
      if(data.length < 100){ 
      is_load = false; 
      }else{ 
        $('div.tovars ul').append(data); 
      } 
       } 
     }); 
    } 
}); 
+0

什么是目前的代码问题似乎是好的,但'postfields'一部分。 '$ postdata'应该使用['http_build_query'](http://ee1.php.net/http_build_query)来处理。目前的问题是什么? – Eugene

回答

-2
,如果你想将数据发送到其他脚本我推荐使用SoapClient类和SoapServer的例如

第一步做一个SoapServer的你想在哪里,并设置数据:

$srv = new SoapServer('Your_wsdl'); 
    $srv->setClass("ServiceClass",$hdr); 
    $srv->handle(); 

    class ServiceClass { 
    var $data; 

    public function setData($data){ 
      $this->data = $data; 
    } 
    } 

第二步:让SoapClient将数据发送到SoapServer:

 $url = 'Your_wsdl'; 
    $client  = new SoapClient($url, array("trace" => 1, "exception" => 0)); 

和现在ü可以进入服务器的数据是这样的:

 $postData = array(
      'mode' => 'json', 
      'brend' => 'zzz', 
      'page' => 1 
    ); 
    $client->setData($postData); 

//在你做出SoapServer的这种情况下,您的数据设置有:

+1

肥皂?真的吗? – Drumbeg

+0

是的,真的! – ZiupeX

-1

你应该制定像个正常人你的问题。 首先,正确的语法应该是

$.ajax({ 
    url: '/pages/getData/', 
    data: { 
     jsarray : data_send 
    }, 
    type: 'post', 
    dataType: 'html', 
    success: function(data){} 
}); 

然后在PHP你只是做

$php_array = $_POST['jsarray']; 

而且在$ php_array你应该拥有这一切。为什么你制定你将要收到的数据类型为html,当我从你提出问题的方式看来,它不是......? 也... JSON数据的正确格式与周围的“细胞”的名字引号,像这样:

var data_send = { 
    'mode': 'json', 
    'brend': 'zzz', 
    'page': 1 
}; 
+0

我认为这个问题是关于使用PHP进行POST请求,而不是从AJAX调用接收POST数据。 – Drumbeg

+0

我不确定问题是什么... –

+1

说实话,我都没有;) – Drumbeg