Reputation: 440
OnbuttonClick trying to Load Page via .load()
POST method. Generated URL parameters and printed as JSON formatted in button attribute btn-url
.
Issue: Parameter is not passed to .load()
since i'm use javascript variable page
Code:
$(document).ready(function(){
$("#open-content").load($php_self,loadfunctions);
$("#open-content").on( "click", ".tools a", function (e){
e.preventDefault();
$("#open-loading-div").show();
var page = $(this).attr("btn-url");
$("#open-content").load($php_self,page, function(){
$("#open-loading-div").hide();
loadfunctions();
});
});
});
Working Code:
$(document).ready(function(){
$("#open-content").load($php_self,loadfunctions);
$("#open-content").on( "click", ".tools a", function (e){
e.preventDefault();
$("#open-loading-div").show();
/*var page = $(this).attr("btn-url");*/
$("#open-content").load($php_self,{"pndg":"nta%3d","nm":"umfuiefuzhk%3d","dpt":"sfi%3d}, function(){
$("#open-loading-div").hide();
loadfunctions();
});
});
});
I want the JSON stored in page
variable to be passed as parameter to .load()
.
How to pass URL parameters from page
Variable to .load()
function?
Note: $php_self
and page
will access PHP file via POST method
Upvotes: 1
Views: 236
Reputation: 2098
The problem was, that the page
object wasn't a json object
, but a stringified json object
. However, the .load
method from jQuery
accepts strings and plain objects, it does not work with stringified json
. The simple solution was to change the .load
call to this:
$("#open-content").load($php_self,JSON.parse(page), function(){
$("#open-loading-div").hide();
loadfunctions();
});
Upvotes: 1