weixin_33747129 2018-02-16 09:31 采纳率: 0%
浏览 37

PHP-调用ASP.Net MVC操作

I don't know nothing about PHP and required me to call from PHP an ASP.Net MVC page to integrate on the PHP page.

I thought using a ajax call will work and be easier to implement. But it seems not to work.

My code:

<div class="pageContainer">    
    <?php   
        echo 'start debugging';

        $param1=$_GET['param1'];
        $param2=$_GET['param2'];
        $htmlPage = '';

        $parameters = {
            myParam1: $param1,
            myParam2: $param2
        };

        try {
            $.ajax({
                type: 'POST',
                url: 'http://localhost:8080/MyController/MyAction',
                data: $parameters,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                processdata: true,
                success: function(result){
                    try {
                        $htmlPage = result->HtmlReturned;
                    }
                    catch (er) {
                        alert('Error');
                        return false;
                    }               
                },
                async: true,
                crossDomain: false,
                error: function(er){ alert('Error'); }
            });
        } catch (e) {
            echo 'catch';
            alert('Error');
        }

        echo $htmlPage;
    ?>          
</div>

What is wrong? I can't usu AJAX calls? I don't get any error and I can't even debug so I don't know what is wrong. My page simply be all empty, without headers without nothing.

The PHP project isn't mine so I can't include any extension or something like that.

  • 写回答

1条回答 默认 最新

  • weixin_33717298 2018-02-16 10:07
    关注

    Like @RiggsFoly said currently my ajax call wasn't being interpreted as javascript. So I transformed my code to fully JS code and wrapped it in a <script> tag.

    I don't know how, I can access in JS to param1 and param2 variables in $_GET['param1'] and $_GET['param2'].

    So, now my code is much clearer and working:

    <script type="text/javascript">
        $(document).ready(function()
        {           
            var parameters = {
                myParam1: param1,
                myParam2: param2
            };
    
            try {
                $.ajax({
                    type: 'POST',
                    url: 'http://localhost:8080/MyController/MyAction',
                    data: parameters,
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    processdata: true,
                    success: function(result){
                        try {
                            $(".pageContainer").html(result.HtmlReturned);
                        }
                        catch (er) {
                            alert('Error');
                        }               
                    },
                    async: true,
                    crossDomain: false,
                    error: function(er){ alert('Error'); }
                });
            } catch (e) {
                alert('Error');
            }
        });
    </script>
    
    <div class="pageContainer">        
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私