letsworktogether letsworktogether - 4 months ago 18
Javascript Question

jquery send post value to another page and load in current page. Show more, display more button

I'm sorry if I cotnfused people. The jquery code belows is suppose to load a web page into the current webpage such as when you hit load more/show more results. The page I'm trying to load into the current page is littlebitego3.php. I can send an input value from the current page to littlebitego3.php and load littlebitego3.php but the page loads in the current page without littlebitego3.php page receiving the value of the input though in a pop up window that the jquery code creates I can see the page littlebitego3.php with the value but it loads a page with a blank since the value in the load somehow doesn't get updated. So my question would be where in the code do i put
$("#div1").load("littlebitego3.php");
because as of right now its misplace and not in the correct spot. I need to configure the post code with the load code but do not know how to do it.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4 /jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("littlebitego3.php");
$.post("littlebitego3.php",
{
name: $("#test").val(),
city: "Duckburg"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
}
);
});
});
</script>


<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

<button>Get External Content</button>

<p>Name: <input type="text" id="test" value="3"></p>

<button>Show Value</button>


here is the code for page littlebitgo3.php


$name2 = $_POST['name'];
echo $name2;
}

?>


UPDATE coded that works below

<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("littlebitego3.php",{
name: $("#test").val(),
city: "Duckburg"
});


});
});
</script>

Answer

Reading the .load() documentation looks like you can provide an object with the request, so you're actually making a POST request and then loading it.

$("#div1").load("littlebitego3.php",{
  name:  $("#test").val(),
  city: "Duckburg"
});

Can't really test it, but I guess something like this could work.