2014-03-07 3 views
0

안녕하세요 저는 아약스를 사용하여 다른 변수에 내 변수를 보내는 문제가 있습니다. 내 문제는 기본 페이지에서 요소의 ID를 얻는 중입니다. 그것의 편집 작업.Ajax가 다른 페이지에 변수를 게시하지 않습니다.

메인 페이지 모달 :

<a href='javascript:' data-id={$row['customer_id']} class='btn small bg-blue-alt tooltip-button modal-customeredit' data-placement='top' title='Edit'><i class='glyph-icon icon-edit' ></i> 

    </a> 
가 같은 페이지에 모달 열립니다

:

<div class="hide" id="modal-projedit" title="Edit Project Info"> 
<div class="pad10A"> 
<h3>Edit Project Info</h3> 
<p class="font-gray-dark"> Fides Admin uses colors & styles from both the default theme color schemes and the included core color helpers. </p> 
<div class="divider mrg25B"></div> 
<form id="project-edit" action="" class="col-md-12 center-margin" method=""> 
<div class="form-row"> 
<div class="form-label col-md-3"> 
<label for="name"> 
    Project Name: 
    <span class="required">*</span> 
    </label> 
</div> 
<div class="form-input col-md-9"> 
<input id="project_name" name="project_name" placeholder="Name" data-required="true" class="parsley-validated" type="text"> 
</div> 
</div> 
<div class="divider"></div> 
<div class="form-row"> 
<div class="form-input col-md-8 col-md-offset-3"> 
<a href="javascript:;" class="btn medium primary-bg radius-all-4" id="project-edit-valid" onclick="javascript:$('#project-edit').parsley('validate');" title="Validate!"> 
    <span class="button-content"> 
    Update 
    </span> 
    </a> 
</div> 
</div> 
</form> 
    </div>  
</div> 

SCRIPT :

$(".modal-customeredit").click(function() { 


     var myGroupId = $(this).data('id'); 
      alert(myGroupId);   
      $.ajax({ 
       type: "POST", 
       url: "sample.php", 
       data: { id: myGroupId }, // data retrieve on server-side ($_POST['id']) 

      }) 




     $("#modal-customeredit").dialog({ 
     modal: true, 
     minWidth: 700, 
     minHeight: 200, 
     dialogClass: "modal-dialog", 
     show: "fadeIn" 
     }); 
     $('.ui-widget-overlay').addClass('bg-black opacity-60'); 

    });   

    }); 
,
+0

시도를 얻을 @Igor PHP 코드 –

+1

무엇인지 확인합니다 seenath의 코드 @를 사용할 필요가 것입니다 : 그래서? ...... – zerkms

+0

'$ (this) .data ('id');를'$ (this) .attr ('data-id')로 대체하고, –

답변

0

alert의 내용을 언급하지 않았습니다.

아약스 요청이 좋았 기 때문에 Null 값을 보여 주긴하지만.

내 내기가 당신의 선택에 간다,이 시도 : (따옴표)

var myGroupId = $(this).attr('data-id'); 
+0

응답이 없습니다. sample.php 페이지 – user3386898

0

HTML :

<a href="javascript:void(0)" data-id="{$row['customer_id']}" class="..."> 
    <i class='glyph-icon icon-edit' ></i> 
</a> 

jQuery를 (폭 데이터 ID와 콜백) :

$(".modal-customeredit").click(function() { 
    var myGroupId = $(this).attr('data-id'); // data-id 
    $.ajax({ 
     type: "POST", 
     url: "sample.php", 
     data: { id: myGroupId }, 
    }).done(function(response) { // data returned by server 
     var d = $('<div id="dialog">'+response+'</div>').appendTo('body'); 
     d.load(function(){ 
      $("#dialog").dialog({ 
       modal: true, 
       minWidth: 700, 
       minHeight: 200, 
       dialogClass: "modal-dialog", 
       show: "fadeIn" 
      }); 
      $('.ui-widget-overlay').addClass('bg-black opacity-60'); 
     }); 
    }); 
}); 
1

다음을 시도해보십시오.

Change the ajax function, 
var myGroupId = $(this).attr('data-id'); // data-id 
data = {'id':myGroupId }; 
$.ajax({ 
      type: "POST", 
      url: "sample.php", 
      data: data, // data retrieve on server-side ($_POST['id']) 
      success:function(response){ 
      alert(response); //do the rest of operations. 
      } 

     }); 
+0

에서이 echo.but 만 응답으로 id 값을 얻을 수 있습니다. 그러나 샘플에 반향 할 수는 없습니다. PHP page.can 당신이 도와 드릴까요? – user3386898

+0

@ user3386898, sample.php에 echo $ _POST [ 'id']가 있으면 응답으로 ID가 표시됩니다. – sreenath

0

data-id 속성에서 PHP 코드에 echo를 사용하기 때문에이 값을 얻을 수 없습니다. 이것은 당신의 HTML

<a href="javascript:void(0)" data-id="<?php echo $row['customer_id']?>" class="..."> 
    <i class='glyph-icon icon-edit' ></i> 
</a> 

을 어떻게 당신이 당신의 myGroupId을 경고하기 위해 값을

관련 문제