fanboime Posted April 24, 2014 Share Posted April 24, 2014 Here's my script $( "#button" ).button(); $( "#button" ).click(function( event ) { <?PHP ... ?> }); And here's the input tag <input id="button" type="submit" value="Add" name = "subBtn" /> Whenever i click the button it triggers postback how can i avoid this? Link to comment https://forums.phpfreaks.com/topic/287991-how-to-avoid-postback-on-jquery-button-click-in-php/ Share on other sites More sharing options...
gristoi Posted April 24, 2014 Share Posted April 24, 2014 $( "#button" ).click(function( event ) { event.preventDefault();}); Link to comment https://forums.phpfreaks.com/topic/287991-how-to-avoid-postback-on-jquery-button-click-in-php/#findComment-1477169 Share on other sites More sharing options...
fanboime Posted April 25, 2014 Author Share Posted April 25, 2014 $( "#button" ).click(function( event ) { event.preventDefault(); }); I've tried this and whenever i click my button nothing is happening... Link to comment https://forums.phpfreaks.com/topic/287991-how-to-avoid-postback-on-jquery-button-click-in-php/#findComment-1477226 Share on other sites More sharing options...
DavidAM Posted April 25, 2014 Share Posted April 25, 2014 $( "#button" ).click(function( event ) { <?PHP ... ?> PHP is executed on the SERVER before the page gets to the user. It is not possible to execute PHP code directly from JavaScript. You would have to use AJAX to send a request to the server to execute some PHP code. Link to comment https://forums.phpfreaks.com/topic/287991-how-to-avoid-postback-on-jquery-button-click-in-php/#findComment-1477233 Share on other sites More sharing options...
fanboime Posted April 25, 2014 Author Share Posted April 25, 2014 PHP is executed on the SERVER before the page gets to the user. It is not possible to execute PHP code directly from JavaScript. You would have to use AJAX to send a request to the server to execute some PHP code. Can you please give a tutorial? Link to comment https://forums.phpfreaks.com/topic/287991-how-to-avoid-postback-on-jquery-button-click-in-php/#findComment-1477238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.