Jquery success

Discussion in 'jQuery' started by cavendano, Jun 17, 2010.

  1. #1
    I am having some difficulty with this script:

    <script type="text/javascript">
    
    	function register(){
    var uname = "<?=$session['session_key'];?>";
    		$.ajax({
    			type: "POST",
    			url: "http://myurl.com/test/submit_data.php",
    			data: 	"username=" + uname,
    			success: function(html){
    				$("#response").html(html);
    			}
    		});
    		
    		}
    	
    	</script>
    HTML:
    Then for html:
    
    <a href="javascript:register()"><img src="http://myurl.com/themes/images/stp.jpg" class="imglink" border=0/></a> 
    <div id="response"></div>
    HTML:

    I just want the div to echo whatever submit_data.php echo's.
     
    cavendano, Jun 17, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    And what error does the script show?
     
    s_ruben, Jun 18, 2010 IP
  3. getlandersgetpaid

    getlandersgetpaid Guest

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    stick an alert() or a console.log() in there to check your function is being called. Or add an event handler to it like this:
    
    $('a.imglink').click(function(){
        register();
    });
    Code (markup):
     
    getlandersgetpaid, Jun 23, 2010 IP
  4. GFX_Lover

    GFX_Lover Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Use normal JavaScript, if this ain't working.
    
    function register(){
    with(x = new XMLHttpRequest()) open("POST", "http://myurl.com/test/submit_data.php", false), setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), send(post);
    document.getElementById("id_of_div").innerHTML = x.responseText;
    
    }
    Code (markup):
     
    GFX_Lover, Jun 29, 2010 IP