![](/img/trans.png)
[英]How to declare this function in jQuery? $(document).ready is not working
[英]How to redirect with document ready function in jquery
我想在調用DOM后進行重定向。 這是我的劇本。
<script>
$(document).ready(function(){
$.get("<?php echo $url; ?>", function(data, status){
alert(data);
});
});
</script>
但是我想這樣做,任何人都不能幫助我。 我更新了編碼。如果我使用window.location.href ='trip_details.php'並且警告框不起作用。
$username="cde-stng";
$password="12345666";
$msg="Welcome To Safetrip Nigeria";
$url="http://121.241.242.114:8080/bulksms/bulksms?username=".$username."&password=".$password."&type=0&dlr=1&destination=".$mobile."&source=".$mobile."&message=".$msg;
<script>
$(document).ready(function(){
$.get("<?php echo $url; ?>", function(data, status){
//alert(data);
window.alert('Trip Closed');
window.location.href='trip_details.php';
});
});
</script>
您正在函數之間添加alert()
。
刪除此行window.alert('Trip Closed') window.location.href='trip_details.php';
然后添加
window.location.href='trip_details.php';
$ url和$ .get在這里有什么用? 請讓我知道您要在這里實現的目標。
據我了解,加載DOM時,您想顯示警報消息“ Trip Closed”,然后重定向到trip_details.php。 如果是這樣,則不需要$ .get。
您可以嘗試以下方法:
$(document).ready(function(){
alert("Trip Closed");
window.location.href='trip_details.php';
});
希望這可以幫助。
和平! xD
我看不到您的代碼有任何問題。 您應該調查AJAX請求。 您可以嘗試PostMan執行GET請求並檢查返回的內容。
如果存在與訪問控制有關的錯誤,則可以對請求使用dataType: 'jsonp'
。 當我使用Google API時,這解決了我的問題。
嘗試使用此命令在控制台中記錄從服務器返回的數據:
$.ajax({
method: "GET",
url: "<?php echo $url; ?>",
dataType: 'jsonp'
}).done(function(data){
console.log(data);
});
如果沒有錯誤,您可以嘗試以下操作:
$.ajax({
method: "GET",
url: "<?php echo $url; ?>",
dataType: 'jsonp'
}).done(function(data){
alert( "Trip Closed" );
window.location.href='trip_details.php';
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.