php - Ajax Get Syntax -


i 've read few tutorials ajax http request, somehow couldn't understand enough build syntax need.

var path = $(this).data('path');     $.get('http://example.ro/index.php?page=contract.php&path='+path, function(){      }); 

what try achieve change url (http://example.ro/index.php?page=contract.php) , without reloading page,so can use path value later use in query or other action,in same page.but url doesnt change (it must &path=value @ end),so can't catch value like:

if(isset($_get['id'])){ /do } 

is syntax wrong? or cant in way? please!

update

$(document).on('click','tr.listcontractrow', function(e){

   var path = $(this).data('path');     $.ajax({   type: 'get',     url: 'contract.php',     data: {id: path},     success: function(result) {        console.log(result)     },     error: function() {      } });   }); 

the variable path value taken php content,and want take ajax , return can catch php.

right syntax ajax request made jquery:

$.ajax({       type: 'get',         url: 'yourphpscript.php',         data: {           key1: value1,           keyn: valuen         },         success: function(result) {           // executed on status 200 ok           console.log(result) // check sent page         },         error: function() {           //to executed on status 500 error         }     }); 

this pretty basic syntax.

let's assume on page. , want call ajax request, it, store in page, , send later php. submit or ajax.

so step1:

$.ajax({       type: 'get',         url: 'givemepath.php',         data: {           key1: value1,           keyn: valuen         },         success: function(result) {           // pretty ugly, functional.           window.path = result.path;           // or if plan submit form prepare hidden field id myhiddenfield           $.('#myhiddenfield').val(result.path);         },         error: function() {           //to executed on status 500 error         }     }); 

your givemepath.php

<?php   $path = ...some php code....   header("content-type: application/json");   echo json_encode(array("path" => $path)); ?> 

later when want use again value in page

$.ajax({       type: 'get',         url: 'sendpathbacklater.php',         data: {           path: window.path,           otherdata: otherdata         },         success: function(result) {           //sent it!         },         error: function() {           //to executed on status 500 error         }     }); 

or submit form.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -