2013-05-18 5 views
0

난 그냥 jquery dialog와 나는 두 가지 형태, page1.phppage1.php에서 page2.php로드 파일이

php form submit

과 혼동, 나는 <a> 링크

<a id="addNew"> Add New </a> 
<div id="myDiv"> 
     <!-- load 'page2.php' file using this div --> 
</div> 

을하고 난 클릭하면 이 링크에서는 양식 값을 사용하여 jquery 대화 상자에 page2.php 파일을로드하십시오.

내 스크립트

<script> 
    $("#addNew").click(function() { 
     $("#myDiv").load('page2.php').dialog({modal:true}); 
    }); 
</script> 

이 스크립트는 page2.php 파일을 잘 부하를 작동합니다. 나는 그것이 page2.phpre-directed 될 것 page2.php의 형태로 값을 제출할 때

이제 내 질문에,

입니다. 하지만 나는 내 page1.php과 함께 있고 싶어합니다.

어떻게해야합니까? 미리 감사드립니다.

답변

0

페이지를로드 할 때 ajax 호출을 사용하여 양식을 제출하는 ajaxForm을 사용할 수 있습니다.

HTML :

<form id="login" action="YOUR_FILE" method="post"> 
    <label>Name:</label> 
     <input type="text" name="name" /><br /> 

    <label>Password:</label> 
     <input type="password" name="pass" /><br /> 

    <input type="submit" name="submit" value="Login" /> 
</form> 

자바 스크립트 : 예를 들어

function processJson(data) { 
    // your code goes here 
} 
$("#login").ajaxForm({ 
    dataType: 'json', 
    success: processJson // what to do when call succeed 
}); 

좋은 하루 되세요!

1

양식을 제공하지 않은 방법으로 보는 것은 가정 만 할 수 있습니다.

<form id="some_form" action="page2.php" method="post"> 
    <input type="text" name="user_name"/> 
    //a collection of form elements 
<form> 

그런 다음 아약스를 사용하고 기본 동작에게 page2.php 파일에 다음

$(document).on('submit', '#some_form', function(e){ 
    e.preventDefault(); //stop form from redirecting, also stops sending of data 
    var $this = $(this); // cache form object for performance 
    $.ajax({ 
     url: $this.prop('action'), 
     type: $this.prop('method'), 
     data: { 
      handle_form: 'ajax', 
      form_data : $this.serializeArray()//array of objects 
     }, 
     success:function(data){ 
      //data is what is returned from the server if successful 
     } 
    }); 
    return false; //just another example of stopping form submit, don't need both 
}); 

을의에서 불과 필드의 존재를 확인, 그것을 방지하면서, 양식 이벤트를 제출 캡처합니다.

if(isset($_POST['user_name']) && $_POST['handle_form'] == 'ajax'): 

    //your form is trying to be submit 
    //handle the submission 
    echo 'We submit the form!'; //is the 'data' in our success function 

elseif(isset($_POST['user_name']) && !isset($_POST['handle_form'])): 

    //regular form submission, no ajax, no javascript. 

endif;  
+0

내 입력 양식은'page1.php'가 아닌'page2.php'에서만 볼 수 있습니다. 'page1.php'는'jquery dialog'를'page2.php'로로드하는 링크 만 가지고 있습니다. – Ranjith

+0

예, 나는 장래의 모든 요소에 페이지를로드 할 수 있도록'.on()'메소드를 사용했습니다. 페이지로드시 존재 하던지 또는 나중에 추가되었는지에 관계없이'# some_form' 인 두 번째 인수와 일치시킵니다. 나는 이미 너를 위해 그것을 생각했다. – Ohgodwhy

+0

그리고''PHP request '를 사용하여'submit form of page2.php'에 대한 코드를 이미 작성했습니다. – Ranjith