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 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配