2010-08-12 4 views
0

내 문제를 heres. 내 코드의 첫 번째 화재가 완벽하게 작동하지만 자바 스크립트 (페이지를 새로 고치는 대신)를 사용하여 제출 단추를 다시로드합니다. 아약스와 관련이없는 모든 것은 두 번째 클릭에서 제대로 실행되지만, 다음 번에 버튼을 클릭하면 아약스가 실행되도록 할 수 없습니다. 여기

$("#edit_company_basic").live('click', function() 
    { 
     //get current value of button 
     var btnText = $("#submit_company_update").val(); 

//on click the button becomes disabled and value changes to Please Wait 
     $("#submit_company_update").attr("disabled", true); 
     $("#submit_company_update").attr("value", "Please wait"); 

//this one add a loader gif and a updating company message 
     $('#button_container').append("<div id='update'><center><img id='loading' src='images/icons/ajax-loader (1).gif' />&nbsp;<font color='red'>Updating company</font></center></div>"); 


//These variables are used for the ajax datastring 
     var name = $("#company_name").val(); 
     var bio = $("#company_bio").val(); 
     var forum_url = $("#forum_url").val(); 
     var collection = $("#collection :selected").text(); 
     var fuel = $("#fuel :selected").text(); 
     var repair = $("#repair :selected").text(); 
     var tickets = $("#tickets :selected").text(); 
     var dataString = 'company_name='+ name + '&bio=' + bio + '&forum=' + forum_url + '&collection=' + collection + '&repair=' + repair + '&fuel=' + fuel + '&ticket=' + tickets; 
     $.ajax({ 
      type: "POST", 
      url: "library/update_company.php", 
      data: dataString, 
      success: function() 
      { 

//On success I give the loader a little more time before anything happens I then re-enable the button allowing the user to be able to click it and give them a message that the copmany has been successfully updated. 
      setTimeout(function(){$("#submit_company_update").attr("value", btnText); $("#submit_company_update").removeAttr('disabled'); $("#update").html("<center><font color='green'>Company has been updated</font></center>"); }, 1550); 

//Here I just give the company updated message a few seconds before I remove it. 
       setTimeout(function(){$("#update").fadeOut(1000); }, 2200); 
      } 
     }); 

    }); 

이 버튼을 다시 한 번 나는 아약스 실행을 할 수있는 방법 사람이 어떤 아이디어가 있습니까 모든 JScript를

<tr> 
      <td colspan="2" id="submit_form"><div id="button_container"><center><input type="submit" name="submit_company_update" id="submit_company_update" value="Edit Company" /></center></div></td> 
     </tr> 

을에 관여 내 HTML입니다 : 여기

내 코드입니다 다시 사용할 수 있습니까? 무슨 일이 일어나면 버튼을 다시 클릭하면 에이잭스가 실행되지 않습니다. 사전에

감사합니다,

Jefffan24

UPDATE 그래서 여기

해당 페이지에서 내 모든 자바 스크립트 코드 :

<script type="text/javascript"> 
$(document).ready(function(){ 
//$("#warning_price").hide(); 
$(".toggle_container").hide(); 

//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state) 
$("#company_name").click(function(){ 
    $(".toggle_container").toggleClass("active").slideDown("normal"); 
}); 
$("#company_name").blur(function(){ 
    $(".toggle_container").slideUp('normal'); 
}); 

//This displays a warning message if they don't have permission to this part of the site. 
$("#noperm").html('<div class="ui-widget" style="width:650px; margin:0 auto;"><div class="ui-state-highlight ui-corner-all" style="padding: 0 .7em;"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em; margin-top:3px;"></span><strong>Error:</strong><br /> That was a heck of try but you do not have permission to access this area.</p></div></div> '); 


//This is a jQuery character count plugin, just setting options and what not 
var options2 = { 
'maxCharacterSize': 450, 
'textFontSize': '12px', 
'textColor': '#000000', 
'warningColor': '#FF0000', 
'originalStyle': 'originalDisplayInfo', 
'warningStyle': 'warningDisplayInfo', 
'warningNumber': 100, 
'displayFormat': '#input Characters | #left Characters Left | #words Words' 
}; 
var options1 = { 
'maxCharacterSize': 255, 
'textFontSize': '12px', 
'textColor': '#000000', 
'warningColor': '#FF0000', 
'originalStyle': 'originalDisplayInfo', 
'warningStyle': 'warningDisplayInfo', 
'warningNumber': 40, 
'displayFormat': '#input Characters | #left Characters Left | #words Words' 
}; 
$('#company_bio').textareaCount(options2); 
$('#company_name').textareaCount(options1); 
$('#forum_url').textareaCount(options1); 
//End the counter 


//Create Select Boxes (using for loops to make 1-50, 1-90, and 1-90 as options 
var minimum = 1; 
var max_col = 50; 
var max_assist = 90; 
var i = 1; 
var def_collection = <?php echo $collection; ?>; 
var def_repair = <?php echo $repair; ?>; 
var def_fuel = <?php echo $fuel; ?>; 
var def_tickets = <?php echo $ticket; ?>; 
//Select boxes for Collection 
$("#tdCollection").append("<select id='collection' name='collection'>"); 



for(i = 1;i <= max_col; i++){ 
    if(i == def_collection){ 
     $("#collection").append("<option selected='selected'>" + i + "</option>"); 
    } 
    else { 
     $("#collection").append("<option>" + i + "</option>"); 
    } 
} 
$("#tdCollection").append("</select>%"); 

//Select boxes for Repair 
$("#tdRepair").append("<select id='repair' name='repair'>"); 
for(i = 1;i <= max_col; i++){ 
    if(i == def_repair){ 
     $("#repair").append("<option selected='selected'>" + i + "</option>"); 
    } 
    else { 
     $("#repair").append("<option>" + i + "</option>"); 
    } 
} 
$("#tdRepair").append("</select>%"); 

//Select boxes for Fuel 
$("#tdFuel").append("<select id='fuel' name='fuel'>"); 
for(i = 1;i <= max_col; i++){ 
    if(i == def_fuel){ 
     $("#fuel").append("<option selected='selected'>" + i + "</option>"); 
    } 
    else { 
     $("#fuel").append("<option>" + i + "</option>"); 
    } 
} 
$("#tdFuel").append("</select>%"); 

//Select boxes for tickets 
$("#tdTickets").append("<select id='tickets' name='tickets'>"); 
for(i = 1;i <= max_col; i++){ 
    if(i == def_tickets){ 
     $("#tickets").append("<option selected='selected'>" + i + "</option>"); 
    } 
    else { 
     $("#tickets").append("<option>" + i + "</option>"); 
    } 
} 
$("#tdTickets").append("</select>%"); 

//End the select box code. 

//On form submit! 
$("#edit_company_basic").live('click', function() 
{ 

    var btnText = $("#submit_company_update").val(); 
    $("#submit_company_update").attr("disabled", true); 
    $("#submit_company_update").attr("value", "Please wait"); 
    $('#button_container').append("<div id='update'><center><img id='loading' src='images/icons/ajax-loader (1).gif' />&nbsp;<font color='red'>Updating company</font></center></div>"); 
    var name = $("#company_name").val(); 
    var bio = $("#company_bio").val(); 
    var forum_url = $("#forum_url").val(); 
    var collection = $("#collection :selected").text(); 
    var fuel = $("#fuel :selected").text(); 
    var repair = $("#repair :selected").text(); 
    var tickets = $("#tickets :selected").text(); 
    var dataString = 'company_name='+ name + '&bio=' + bio + '&forum=' + forum_url + '&collection=' + collection + '&repair=' + repair + '&fuel=' + fuel + '&ticket=' + tickets; 
    $.ajax({ 
     type: "POST", 
     url: "library/update_company.php", 
     data: dataString, 
     success: function() 
     { 
      setTimeout(function(){$("#submit_company_update").attr("value", btnText); $("#submit_company_update").removeAttr('disabled'); $("#update").html("<center><font color='green'>Company has been updated</font></center>"); }, 1550); 
      setTimeout(function(){$("#update").fadeOut(1000); }, 2200); 
     } 
    }); 

}); 
}); 


</script> 

가 그리고 여기에 내 모든 HTML

<form method="post" action="" name="edit_company_basic" id="edit_company_basic"> 
     <table class="company" cellspacing="0" cellpadding="7" style="width:550px; margin:0 auto;"> 
     <!--<tr> 
      <td colspan="4" style="padding:0px;"><img src="<?php echo $image; ?>" alt="<?php echo $name; ?> Logo" /></td> 
     </tr>--> 
     <tr> 
      <th colspan="2" class="th_bold"><center>Basic Information</center></th> 
     </tr> 
     <tr> 
      <th width="120">Company Name:</th> 
      <td width="400" valign="top"><input type="text" name="company_name" class="company_name" id="company_name" value="<?php echo $name; ?>" style="width:395px;" /><br /> 
      <div class="toggle_container"> 
       <div class="block"> 
        <span id="warning_price" style="background:#FFF9F9; border:1px solid red; min-width:395px; width:395px; padding:5px;"><strong>Warning:</strong> Editing the name will cost the company $2000</span> 
       </div> 
      </div> 


      </td> 
     </tr> 
     <tr> 
      <th valign="top">Company Bio:</th> 
      <td width="400"><textarea name="company_bio" id="company_bio" style="width:390px; margin:0 auto; padding:5px; height:150px;"><?php echo $bio; ?></textarea></td> 
     </tr> 
     <tr> 
      <th>Forum URL:</th> 
      <td><input type="text" name="forum_url" id="forum_url" value="<?php echo $forum; ?>" style="width:395px;" /></td> 
     </tr> 
     <tr> 
      <th>Default Collection:</th> 
      <td id="tdCollection"></td> 
     </tr> 
     <tr> 
      <th>Default Repair Assistance:</th> 
      <td id="tdRepair"></td> 
     </tr> 
     <tr> 
      <th>Default Fuel Assistance:</th> 
      <td id="tdFuel"></td> 
     </tr> 
     <tr> 
      <th>Default Ticket Assistance:</th> 
      <td id="tdTickets"></td> 
     </tr> 
     <tr> 
      <td colspan="2" id="submit_form"><div id="button_container"><center><input type="submit" name="submit_company_update" id="submit_company_update" value="Edit Company" /></center></div></td> 
     </tr> 
     </table> 
     </form> 

누군가가 나를 알게되면, 거기에 몇 가지 PHP가 있지만 그 중 아무도 내가 사용하는 관광 명소가 어떤 문제를 일으키지 않는 것으로 믿지 않는 문제가 없습니다. 귀하의 "클릭"처리기가 ​​false을 반환해야

+0

'나는 긴 검색된 '태그, 장기. – Pointy

+0

롤 예, 내가 빨리 글꼴을 사용하는 대신 CSS를 바꿀 필요가있을 때. – jefffan24

+0

원하는 요소에 항상'style = "color : red"'를 사용할 수 있습니다. – Pointy

답변

0

대신 거짓

$("#submit_company_update").attr('disabled', false); 

에 에릭

+0

그건 좋은 조언이지만, 그의 질문에 대한 답변이 아닙니다. – Pointy

+0

고맙습니다. – jefffan24

0

그것을 설정, 해제를 제거하는 removeAttr를 사용하지 마십시오. 그렇지 않으면, "제출"요소의 정상적인 동작, 즉 양식 제출이 발생합니다. 그러면 페이지가 다시로드되고 Javascript가 발생하지 않을 것입니다. (Javascript가 언제 어떻게 실행되는지는 명확하지 않으므로 페이지를 새로 고친 후에 적용되지 않는 이유는 확실하지 않습니다.)

+0

글쎄, 내가 Ajax를 사용하고있는 페이지 재로드를 제거하려고하고있다. 양식은 처음으로 다시로드하지 않고도 작동하지만 버튼을 다시 클릭하면 아약스가 실행되지 않습니다. 페이지를 다시로드하지 않고도 계속해서 다시 작동하도록 할 수 있기를 바랬습니다. – jefffan24

+0

글쎄, 여기에 아마 당신이 게시 한 코드에서 더 많은 일이있을 것입니다. 지금까지 어떤 종류의 디버깅을 했습니까? – Pointy

+0

디버깅 코드를 어디에 두어야할지 모르겠다. IE를 사용하여 오류가 발생했는지 알 수는 없지만 그 다음에는 무엇을해야할지 모른다. 위의 모든 대담한 업데이트 아래 자바 코드와 html 코드가 있습니다. – jefffan24

0

나는이 작업을 수행 할 수 없으며 그렇게해야합니다. 내가 무엇을하기로 결정하는 것은 아약스를 잊지 그냥 클릭의 버튼을 해제 한 다음 내가 거기에서 PHP를 사용하는 표준

$("form id here").submit(); 

에 제출 한 다음 다시로드에 그들이 그것의 업데이트 된 것을 알리는 좋은 메시지를 넣습니다 . 모든 도움

모두 감사합니다 내가 정말 감사하고, 내가 시간이있을 때 잘하면 언젠가는 내가 그것을 다시 방문하고 작동 할 수 있습니다)

먼저
관련 문제