2010-07-30 114 views
0

我使用CakePHP我有2個環節:解決雙重URL問題..?

<a href="#" tabindex="1" onclick="base_load_demo1('http://www.boxyourtvtrial.com/widget/beer/main/');" >beer</a> 
<a href="#" tabindex="2" onclick="base_load_demo('http://www.boxyourtvtrial.com/widget/cocktail/main/');">cocktail</a> 

用下面的JavaScript:

var Url1 = "http://www.boxyourtvtrial.com/widget/cocktail/main/"; 
var Url2 = "http://www.boxyourtvtrial.com/widget/beer/main/"; 
var Url3 = "http://www.boxyourtvtrial.com/widget/beer/mini/"; 

function base_load_demo(Url) { 
    remoteCall(Url1,"","mainLeftContent"); 
    //remoteCall("SCRIPT_PATH","QUERY_STRING","TARGET_FUNCTION"); 
} 

function base_load_demo1(Url2) { 
    remoteCall(Url2,"","mainLeftContent"); 
    //remoteCall("SCRIPT_PATH","QUERY_STRING","TARGET_FUNCTION"); 
} 

當我點擊它顯示通過Ajax調用其內容的第一個鏈接,但是當我點擊第二如下鏈接其給錯誤:

Missing Controller

Error: Http:Controller could not be found.

Error: Create the class Http:Controller below in file: app/controllers/http:controller.php

<?php 
class Http:Controller extends AppController { 

    var $name = 'Http:'; 
} 
?> 

Notice: If you want to customize this error message, create app/views/errors/missing_controller.ctp

,並在FireFox控制檯選項卡

POST http://www.boxyourtvtrial.com/widget/beer/main/http://www.boxyourtvtrial.com/widget/cocktail/main/

我們如何解決這個雙URL調用在同一時間?

<script type="text/javascript" src="http://www.boxyourtvtrial.com/widget/cocktail/main/js/common.js"></script> 
在頭

var xmlHttp; 
var uri = ""; 
var callingFunc = ""; 
var sResponse = new Array(); 



function remoteCall(sUrl, sQueryStr, sCalledBy) 
{ 
    alert(sUrl); 
    var resStr = ""; 
var str = " { "; 
if(sQueryStr != "") { 
    var arr1 = new Array(); 
    arr1 = sQueryStr.split("&"); 
    if(arr1){ 
     for(i=0;i<=arr1.length;i++) 
     { 
      if(arr1[i] && arr1[i] != "") 
           { 
       var arr2 = new Array(); 
       arr2 = arr1[i].split("="); 
       str += arr2[0]+":'"+arr2[1]+"' ,"; 

       } 
     } 
    } 
}     

    str += " tp: 'tp' } "; 


    $.ajax({ 
     type: "GET",  
     url: sUrl, 
     data: sQueryStr, 
     dataType: "html", 
     success: function(data) { 
      $("#"+sCalledBy).html(data); 
      //jih(sCalledBy,data); 
     } 
    }); 

    /* $.get(sUrl,sQueryStr,function(data) { 
    jih(sCalledBy,data); 
    });*/ 
} 

function jih(divid,data) 
{ 
     if(document.getElementById(divid)) 
        document.getElementById(divid).innerHTML=data; 
    } 
+0

請**由4個空格**縮進代碼,否則很難閱讀或不可見。 http://stackoverflow.com/editing-help – deceze 2010-07-30 05:38:29

+0

好吧,但現在是什麼解決方案.......... – rajesh 2010-07-30 06:04:01

+0

你看過自己的問題嗎?它有道理嗎?不,因爲你的一半代碼是隱藏的。你如何期待得到答案? – deceze 2010-07-30 06:16:29

回答

1

首次呼叫要麼加載這些頁面後。裏面的common.js是一個叫的函數remoteCall,它覆蓋你的本地remoteCall函數。

內部common.js的爲RemoteCall函數添加

var url= WIDGET_WEG_PATH+scr_url; 

其中WIDGET_WEG_PATH = 「http://www.boxyourtvtrial.com/widget/beer/main/

scr_url = 「http://www.boxyourtvtrial.com/widget/beer/main/(新爲RemoteCall函數的第一參數)

這就是爲什麼你在帖子中獲得url'doubled'。

解決方案:

重命名本地爲RemoteCall功能的東西,是截然不同的。

+0

謝謝傑克解決了我更大的困惑 – rajesh 2010-07-31 12:03:28