如何在ajax url中使用php变量?
我想在AJAX url中使用一个PHP变量。我怎样才能做到这一点 my.php如何在ajax url中使用php变量?,php,ajax,Php,Ajax,我想在AJAX url中使用一个PHP变量。我怎样才能做到这一点 my.php function displayRecords() { $.ajax({ type: "GET", url: "http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=$number&message=$message&sender=INFORM&
function displayRecords() {
$.ajax({
type: "GET",
url: "http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=$number&message=$message&sender=INFORM&type=3",
data: "show="+numRecords+"&pagenum="+pageNum,
cache: false,
beforeSend: function () {
$('#content').html('<img src="loader.gif" alt="" width="24" height="24" style=" padding-left:469px;">');
},
success: function(html) {
$("#results").html( html );
}
});
}
<?php
$message="hi"
$number=8888888888;
?>
函数displayRecords(){
$.ajax({
键入:“获取”,
url:“http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=$number&message=$message&sender=notify&type=3“,
数据:“show=“+numRecords+”&pagenum=“+pagenum,
cache:false,
beforeSend:函数(){
$('#content').html('');
},
成功:函数(html){
$(“#结果”).html(html);
}
});
}
这里我想在AJAX url中使用这些PHP变量
如何实现这一点?将php代码移到js之上,并在js中添加php代码以获取php变量
<?php
$message="hi"
$number=8888888888;
?>
<script>
function displayRecords() {
$.ajax({
type: "GET",
url: "http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=<?php echo $number;?>&message=<?php echo $message;?>&sender=INFORM&type=3",
data: "show="+numRecords+"&pagenum="+pageNum,
cache: false,
beforeSend: function () {
$('#content').html('<img src="loader.gif" alt="" width="24" height="24" style=" padding-left:469px;">');
},
success: function(html) {
$("#results").html( html );
}
});
}
</script>
函数displayRecords(){
$.ajax({
键入:“获取”,
url:“http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=&message=&sender=INFORM&type=3",
数据:“show=“+numRecords+”&pagenum=“+pagenum,
cache:false,
beforeSend:函数(){
$('#content').html('');
},
成功:函数(html){
$(“#结果”).html(html);
}
});
}
尝试以下操作:-
<?php
$message="hi"
$number=8888888888;
?>
function displayRecords() {
$.ajax({
type: "GET",
url: "http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=<?php echo $number; ?>&message=<?php echo $message; ?>&sender=INFORM&type=3",
data: "show="+numRecords+"&pagenum="+pageNum,
cache: false,
beforeSend: function () {
$('#content').html('<img src="loader.gif" alt="" width="24" height="24" style=" padding-left:469px;">');
},
success: function(html) {
$("#results").html( html );
}
});
}
函数displayRecords(){
$.ajax({
键入:“获取”,
url:“http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=&message=&sender=INFORM&type=3",
数据:“show=“+numRecords+”&pagenum=“+pagenum,
cache:false,
beforeSend:函数(){
$('#content').html('');
},
成功:函数(html){
$(“#结果”).html(html);
}
});
}
试试这个:
<script>
function displayRecords() {
var numRecords = '<?php echo hi; ?>';
var pageNum = '<?php echo 8888888888; ?>';
$.ajax({
type: "GET",
url: "http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=
<?php echo $number;?>&message=<?php echo $message;?>&sender=INFORM&type=3",
data: "show="+numRecords+"&pagenum="+pageNum,
cache: false,
beforeSend: function () {
$('#content').html('<img src="loader.gif" alt="" width="24" height="24" style="
padding- left:469px;">');
},
success: function(html) {
$("#results").html( html );
}
});
}
</script>
函数displayRecords(){
var numRecords='';
var pageNum='';
$.ajax({
键入:“获取”,
url:“http://www.bulksmsgateway.in/sendmessage.php?user=Ami&password=74153&mobile=
&message=&sender=通知&type=3“,
数据:“show=“+numRecords+”&pagenum=“+pagenum,
cache:false,
beforeSend:函数(){
$('#content').html('');
},
成功:函数(html){
$(“#结果”).html(html);
}
});
}
将php块移到javascript函数上方。尽管将api凭据放在javascript中让所有人都能看到似乎是一个特别糟糕的想法,但投票反对将api凭据包括在问题中。别再傻了@阿尼尔·库马尔这不是我原来的阿皮奥。。。我们的回答是一样的:)@Khushboo是的,如果你得到了正确的答案,你需要提高投票率,而不是另一个答案——你内心有一点争斗。我喜欢这样@anil Kumar$message和其他php var值在哪里?主持人注意,我已经删除了所有不必要的注释。如果你觉得有必要讨论这些问题,那就去聊天吧。我看不到任何证据表明这是一个抄袭的答案,所以不要再争论了。