SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with calling $ajax function

    I have a problem calling an ajax script from a div id.

    When I go directly to site.com/page.php and click on the id linked to the click event it takes me to a new page that is like site.com/page.php?gm_login_name=&gm_login_pw=&gm_plu_submit=Submit#.

    From this page (with the parameters in the URL) if I click submit the ajax is called successfully. The problem is I dont want the user to have to click twice on the div, how can I solve this problem?? any ideas?

    Code:
    $('.out-div').append('<p class="reward"><input type="text" name = "login"/><br/><input type="submit" name="ajax_call" class ="ajax_call"/></form></p>');
    
    
    $(document).ready(function(){
    			   
    		  $(".ajax_call").click(function(){
    											 
    				  $.ajax({
    						 
    						 url: 'http://localhost/places/password/12345/format/jsonp',
    						 dataType: 'jsonp',
    						 type: 'GET',
    						 success: function(){
    							 
    						  setCookie('user_id',5,7);
    						  
    						  
    						  
    						 // window.location.reload(true);
    							 
    						 }
    
    					   
    					});
    			  
    		  });
    							   });

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by condo123 View Post
    I have a problem calling an ajax script from a div id.

    When I go directly to site.com/page.php and click on the id linked to the click event it takes me to a new page that is like site.com/page.php?gm_login_name=&gm_login_pw=&gm_plu_submit=Submit#.
    That occurs due to the form being submitted, causes by the input field with the submit type.

    If you don't want such a submit to occur, you can use a button element instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •