javascript - Passing Variable to the next page without form or URL extension -


i have link go examplea.php, want have variable pass link. of course condition not using url extensions or form submitting.i search around , people suggest ajax, me not passing variable of file want handle variable when @ examplea.php page. in examplea.php have code example

if(isset($_post['type'])){ $type=$_post['type']; }

with ajax not able handle post variable when reach examplea.php page. in case maybe wrong code.

<a class="example_anchor" href="testb.php/" data-type="activity">m</a>     <script>         $(".example_anchor").on("click", function (e) {         e.preventdefault();         var type = $(this).data();         var link = $(this).attr('href');         $.ajax({             url: link,             type: "post",             datatype: "text",             data: {                  type:type             },             error: function (msg) {                 alert("fail");// error handling             },             success: function (msg) {                 // success handling                       alert("you redirected.");                      window.location.replace(link);              }         });           });      </script> 

personally, i'd set cookie before moving on next page.

$('.example_anchor[data-type]').on('click', function (e) {   document.cookie = `type=${this.getattribute('data-type')}` // note, simplified   return true }) 

then php script should able access $_cookie['type'].


if testb.php not in same path current resource, may need set cookie path property. may want set other properties expires though default expire @ end of session.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -