Advanced Search

Results 1 to 6 of 6

Thread: External Javascript Help

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question External Javascript Help

    I have tell a friend javascript

    Code:
    <script type="text/javascript" language="javascript">
    var http_request = false;
    
      function show_hint ( p_hint_text, p_span ) {
        document.getElementById(p_span).innerHTML = p_hint_text ;
      }
    
      function makePOSTRequest(url, parameters, SpanName) {
        http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
        http_request.overrideMimeType('text/xml');
        }
        } else if (window.ActiveXObject) { // IE
        try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
        try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
        }
        }
        if (!http_request) {
        alert('Cannot create XMLHTTP instance');
        return false;
        }
      
        http_request.onreadystatechange = function() {
        if (http_request.readyState == 4) {
        if (http_request.status == 200) {
        //alert(http_request.responseText);
        result = http_request.responseText;
        document.getElementById(SpanName).innerHTML = result;
        document.getElementById('status').innerHTML = 'Ready'; 
        } else {
        alert('There was a problem with the request.');
        }
        }
        };
        http_request.open('POST', url, true);
        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http_request.setRequestHeader("Content-length", parameters.length);
        http_request.setRequestHeader("Connection", "close");
        http_request.send(parameters);
      }
    
    
      function Contact(obj,SpanName,DivName) {
        var curDateTime = new Date(); //For IE 
        var SpanName = SpanName; 
    
    
        if(DivName == 'tf'){
        var poststr = "sendersname=" + encodeURI( document.getElementById("sendersname").value ) +
      	  				"&sendersemail=" + encodeURI( document.getElementById("sendersemail").value ) +
      	  				"&friendsemail=" + encodeURI( document.getElementById("friendsemail").value ) +
      	  				"&about=" + encodeURI( document.getElementById("about").value ) +
      	  				"&gamename=" + encodeURI( document.getElementById("gamename").value ) +
      					  "&gameid=" + encodeURI( document.getElementById("gameid").value );
        
        //alert (SpanName); 
        makePOSTRequest('<? echo $base_url;?>index.php?action=tellafriendajax', poststr, SpanName);
        }    
        if(DivName == 'tfv'){
        var poststr = "sendersname=" + encodeURI( document.getElementById("sendersname").value ) +
      	  				"&sendersemail=" + encodeURI( document.getElementById("sendersemail").value ) +
      	  				"&friendsemail=" + encodeURI( document.getElementById("friendsemail").value ) +
      	  				"&about=" + encodeURI( document.getElementById("about").value ) +
      	  				"&gamename=" + encodeURI( document.getElementById("gamename").value ) +
      	  				"&verifycode=" + encodeURI( document.getElementById("tafverifycode").value ) +
      					  "&gameid=" + encodeURI( document.getElementById("gameid").value );
        
        //alert (SpanName); 
        makePOSTRequest('<? echo $base_url;?>index.php?action=tellafriendajax', poststr, SpanName);
        }    
    
        if(DivName == 'cf'){
        var poststr = "newcomment=" + encodeURI( document.getElementById("newcomment").value ) +
      	  				"&id=" + encodeURI( document.getElementById("id").value );
        
        //alert (SpanName); 
        makePOSTRequest('<? echo $base_url;?>index.php?action=addcommentajax', poststr, SpanName);
        }
        if(DivName == 'cfv'){
        var poststr = "newcomment=" + encodeURI( document.getElementById("newcomment").value ) +
      	  				"&id=" + encodeURI( document.getElementById("id").value ) +
      					"&verifycode=" + encodeURI( document.getElementById("cverifycode").value );
        
        //alert (SpanName); 
        makePOSTRequest('<? echo $base_url;?>index.php?action=addcommentajax', poststr, SpanName);
        }
       
        document.getElementById(DivName).style.display = 'none';
      }
    </script>
    When I paste this code directly in my page the javascript works fine.
    But when I place it in an external javascript file “mibo.js”
    I remove also the first and last lines:
    Code:
    <script type="text/javascript" language="javascript">
    </script>
    and add this code line instead in my site’s page.

    Code:
    <script type="text/javascript" src="<? echo $base_url;?>js/mibo.js"></script>
    It doesn’t work and I get this massage “There was a problem with the request.”

    Can someone Please help me with this issue.
    Rwanka

  2. #2
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    Sorry. Had to delete the post. My suggestion was no good !
    Last edited by azoomer; 06-24-2010 at 03:18 PM.

  3. #3
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So why do you think guys,
    Why when I put the javascript on external file it will not work anymore.
    Could the problem be with the server?

  4. #4
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    I think the problem is with the link. I can't get this part to work
    src="<? echo $base_url;?>js/mibo.js
    I think would be easier just to link without php, if that is possible in your application. A normal absolute or relative path would probably work fine.

  5. #5
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried also direct html link to mibo.js without using any php but the same result.

  6. #6
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    By the way this just happened after moving to new server, in my previous server the script was working on page and also external, when moving to the new server this script doesn’t work external.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •