2017-09-03 5 views
0
<?php  
$short_des="Harry Potter is a series of fantasy novels"; //initially short_description has this value 
echo '<span><p>About:</p> '.$short_des.'</span>'; //initially i am printing short_des here but after cick of submit i want to update it 
echo '<form class="make_long_form" method="post">'; 
    echo '<input type="text" id="make_descrip_long" method="post" name="make_descrip_long" value="'.$post_read_more['id'].'">'; 
    echo '<input type="submit" id="read_more_button" value="Show more">'; //this is the submit form 
echo '</form>'; 
if(isset($_POST['make_descrip_long'])){ 
$short_description = "Harry Potter is a series of fantasy novels written by British author J. K. Rowling."; //after the click of submit i want to update the value of short_description and update it in the about echo above 
         } 
?> 

私はエコーのshort_desの値を更新するためにajaxを使用する必要があると思います。助けて。送信のクリック後に特定のdivを更新するためにajaxを使う方法は?

+0

この種のアクションでは、JavaScriptだけでいいです.Ajaxの必要はありません。 – Philipp

+0

どうすればいいですか教えてください。 –

+0

別のページからコンテンツをdinamicallyロードする場合は、jqueryとajaxを使用してこれを行う方法についてお答えしました。 –

答えて

0

あなたはjQueryのを使用している場合は、これを試してみてください。

AJAX機能:

function loadDiv(url, element){ 
    $.post(url, {}, function(res){ 
     myDiv.html(res); 
    } 
} 

URLを:あなたはdivの中に入れたいデータが配置されているページをrapresent文字列です。

要素は:更新したいdivがjQueryの中でuは彼のIDセレクタでそれを渡すことができ、次のとおりです。

var element = $("#divID"); 

{}は、ポストとしてURLページに渡されるJSONオブジェクトです。

res変数では、リクエストの応答をHTMLで取得します。