0

I'm having an issue with retrieving the product list from magento . I'm sending a a value using ajax , then I use that value as a filter value for magento soap call, but it 's not working, I couldn't get the product details .

but when I hard coded the value to variable in the same webservice.php file it works ..

What's the fault I have done ...

here is my ajax.php & webservice.php files

ajax.php

// ajax script  
<script>
//item_code is text box , user enter some value to it. 
$('#item_code').live("keyup",function(){

    item_code = $('#item_code').val();

    $.ajax({
        url:"webservice.php",
        type:"POST",
        dataType: "json",
        data : '&item_code= ' + item_code,
        cache:false,
        success: 
        function (data) {

            if (data.successfully_inserted == "passed")
            {

                alert('ok');

            }
            else
            {

                alert('error');
            }
        }
      });
 });

</script>



webservice.php

<?php

//$item_code = 'abc' ;   // This works , I can get the correct result.
$item_code = $_POST['item_code'];  // when I assign $item_code to post data value it does not work. I echo it, data was posted correctly. 

$client = new SoapClient('http://myhost/index.php/api/soap/?wsdl');
$session = $client->login('test', 'test1234');


$filters = array(
 'item_code' => array('where'=>$item_code)
);

/* $filters = array(
 'item_code' => array('like'=>''.$item_code.'%')
); */


$products = $client->call($session, 'catalog_product.list', array($filters) );

print_r($products);

echo '{"successfully_inserted": "passed"}';
4

2 回答 2

2

您可以使用以下方法调试响应吗?

$client->__getLastResponse()

启用跟踪,示例代码

$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
回声“响应:\n”。$client->__getLastResponse() 。"\n";

于 2013-09-17T10:19:55.077 回答
1

您正在以 json 格式发送数据,因此您应该首先对其进行解码,例如

$item_arr = json_decode($this->_getParam('item_code')); 

或者您可以使用简单的 html 类型来发布您的数据

当您在控制器中调用 ajax 函数时,还可以调试 post 值。

希望这会帮助你。

于 2013-09-17T10:29:08.140 回答