Results 1 to 5 of 5

Thread: Ajax not executing properly?? please help asap

  1. #1
    simbawoomba is offline Sugar Community Member
    Join Date
    Dec 2006
    Posts
    13

    Default Ajax not executing properly?? please help asap

    Hi, i have recently built a module for sugarCRM, i am having problems with the ajax working, my module works stand alone without being in sugar, but when i import the files into sugar the Ajax no longer works, it says it is sending the request, however nothing is being executed,

    any suggestions on this?

    thanks alot, any help much appreciated as this module is ready apart from this little probelm

  2. #2
    kpit's Avatar
    kpit is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Dec 2005
    Location
    Memphis, TN
    Posts
    996

    Default Re: Ajax not executing properly?? please help asap

    are you using confilcting libraries for ajax?
    Cheers,

    Max W. Blackmer, Jr.

    Blog
    Phone: +1 (901) 672-2694



  3. #3
    simbawoomba is offline Sugar Community Member
    Join Date
    Dec 2006
    Posts
    13

    Default Re: Ajax not executing properly?? please help asap

    Hi

    i am using the following method to call the ajax, basically in my main code i have this:


    Code:
    	var ajaxRequest;  // The variable that makes Ajax possible!
    
    function tryAjax(){
    
    		try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    }	
    
    
    function ajaxfunctionSaveLoginDetails(){
    
    tryAjax();
    	
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		if(ajaxRequest.readyState == 4){
    	
    		}
    	}
    	
    	
    	if(document.SMSForm.rememberPassword[0].checked==true){
    		var username = document.getElementById('Userkey').value;
    		var password = document.getElementById('Password').value;
    	}else if(document.SMSForm.rememberPassword[1].checked==true){
    		var username = document.getElementById('Userkey').value;
    		var password = "";
    	}else if(document.SMSForm.rememberPassword[2].checked==true){
    		var username = "";
    		var password = "";
    	}
    	
    	var queryString = "?username=" + username + "&password=" + password;
    	
    	ajaxRequest.open("GET", "ajaxSaveLoginDetails.php" + queryString, true);
    	ajaxRequest.send(null); 
    
    }

    and the php file that is being called has the following code:

    Code:
    <?php
    
     	include('db_settings.inc.php');
    
        include('adodb/adodb.inc.php');    # load code common to ADOdb 
        $conn = &ADONewConnection('mysql');    # create a connection 
        $conn->PConnect($dbhost,$dbuser,$dbpass,$dbname);    # connect to MySQL, agora db 
    	
    
    	
    	
    $username = $_GET['username'];
    $password = $_GET['password'];
    
    
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);
    
    	$query = "DELETE FROM login_details";
    	
    	$qry_result = $conn->Execute($query);
    
    	//build query
    $query = "INSERT INTO login_details (Username,Password)";
    $query.=	"VALUES ('".$username."','".$password."')";
    
    	//Execute query
    $qry_result = $conn->Execute($query);
    
    	
    echo "Done";
    
    ?>
    I am not sure what the problem with this is tho?

    Usually the username from the database appears within the username field, however now the field is now filled with this:

    <script type="text/javascript" src="include/javascript/sugar_3.js?s=4.2.0d&c="></script><script type="text/javascript" src="include/javascript/cookie.js?s=4.2.0d&c="></script><link rel="stylesheet" type="text/css" media="all" href="themes/Sugar/calendar-win2k-cold-1.css?s=4.2.0d&c="><script>jscal_today = 1.17024483E+12

    i have no idea where this has come from at all, i hope this helps

    thanks for your help, much appreciated.
    Last edited by simbawoomba; 2007-01-31 at 11:04 AM.

  4. #4
    simbawoomba is offline Sugar Community Member
    Join Date
    Dec 2006
    Posts
    13

    Default Re: Ajax not executing properly?? please help asap

    i have found my problem, but dont know how to fix it,

    basically, the link in this bit of code is wrong

    Code:
    	ajaxRequest.open("GET", "ajaxSaveLoginDetails.php" + queryString, true);
    i know this because if i upload the file to the main sugar directory (ie the same place as where the sugar config file id) then it works, however, i want it to open the file in my module folder which would be located at

    Code:
    	ajaxRequest.open("GET", "modules/SytekSMS/ajaxSaveLoginDetails.php" + queryString, true);
    however this does not seem to work, i have also tried:

    Code:
    	ajaxRequest.open("GET", "/modules/SytekSMS/ajaxSaveLoginDetails.php" + queryString, true);
    but again, it does not work,
    Last edited by simbawoomba; 2007-01-31 at 02:24 PM.

  5. #5
    gofry1 is offline Junior Member
    Join Date
    Nov 2007
    Posts
    1

    Default Re: Ajax not executing properly?? please help asap

    change
    Code:
    var queryString = "?username=" + username + "&password=" + password;
    to
    Code:
    var queryString = "?to_csv=notReally&username=" + username + "&password=" + password;
    note 1: you can use almost anything you want instead of "notRealy"
    not 2: if you like pdfs, you can change to_csv to to_pdf and it will do the same job :-)


    You should normally use ?sugar_body_only=true but this still outputs some trash code :-( Maybe it will be fixed in new release.
    If you want sugar_body_only to work correctly, you have to edit sugar's index.php:

    change line with code (there should be only one such line)
    Code:
    if(empty($_REQUEST['to_pdf']) && empty($_REQUEST['to_csv']))
    to
    Code:
    if(empty($_REQUEST['to_pdf']) && empty($_REQUEST['to_csv']) || !isset($_REQUEST['sugar_body_only'])
    Problems might arise when you update your sugarcrm and index.php gets overwritten. On the other hand, the same might happen to to_csv

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 15
    Last Post: 2007-06-13, 05:18 PM
  2. Help Implementing AJAX
    By simbawoomba in forum Help
    Replies: 0
    Last Post: 2007-01-22, 10:18 AM
  3. AJAX not working on Sugar v4.0.1!
    By gosugar in forum Help
    Replies: 11
    Last Post: 2006-07-31, 06:02 PM
  4. Customer Information (AJAX)
    By jerik in forum Feature Requests
    Replies: 1
    Last Post: 2006-07-12, 04:41 AM

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
  •