views:

125

answers:

1

I am using cakephp I have 2 links:

<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/');"&gt;cocktail&lt;/a&gt;

With the following 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");
}

When I click on the first link it's showing its content through ajax call but when I click on the second link its giving error as follows:

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

and in FireFox console tab

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

How can we solve this dual URL calling at the same time?

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;
    }
+1  A: 

After your first call to either of those pages it loads:

<script type="text/javascript" src="http://www.boxyourtvtrial.com/widget/cocktail/main/js/common.js"&gt;&lt;/script&gt;

in the header. Inside common.js is a function called remoteCall, which is overwriting your local remoteCall function.

The remoteCall function inside common.js adds

var url= WIDGET_WEG_PATH+scr_url;

where WIDGET_WEG_PATH = "http://www.boxyourtvtrial.com/widget/beer/main/"

and scr_url = "http://www.boxyourtvtrial.com/widget/beer/main/" (the first parameter of the new remoteCall function)

This is why you are getting the url 'doubled' in the post.

Solution:

Rename local remoteCall function to something that is distinct.

Jack B Nimble
thanks Jack this solve my bigger confusion
rajesh