[英]PHP - call ASP.Net MVC action
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. 我对PHP一无所知,要求我从PHP调用ASP.Net MVC页面以集成到PHP页面。
I thought using a ajax call will work and be easier to implement. 我以为使用ajax调用会工作并且更易于实现。 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? 我无法使用AJAX通话吗? 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. PHP项目不是我的,因此我不能包含任何扩展名或类似的内容。
Like @RiggsFoly said currently my ajax call wasn't being interpreted as javascript. 就像@RiggsFoly所说,目前我的ajax调用没有被解释为javascript。 So I transformed my code to fully JS code and wrapped it in a <script>
tag. 因此,我将代码转换为完全JS代码,并将其包装在<script>
标记中。
I don't know how, I can access in JS to param1
and param2
variables in $_GET['param1']
and $_GET['param2']
. 我不知道如何在JS中访问$_GET['param1']
和$_GET['param2']
param1
和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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.