javascript - How to get dynamic value from URL -
i studying on angularjs there want load content mysql in reference url value.
the angularjs routeprovider used this:
$routeprovider.when('/page/pages=:pages', { templateurl: 'page.html', reloadonsearch: false });
my dynamic url is:
"<a class='list-group-item' href='#/page/pages=" + slug + "'>" + title + " <i class='fa fa-chevron-right pull-right'></i>" + "</a>"
after that, tried alert url location on phonegap (screenshot attached)
now, want pass pages value ajax result query mysql.
$(function () { //----------------------------------------------------------------------- // 2) send http request ajax http://api.jquery.com/jquery.ajax/ //----------------------------------------------------------------------- jquery.ajax({ url: 'http://keralapsctuts.com/app/index.php', //the script call data data: "pages="+pages, //you can insert url argumnets here pass api.php example "id=5&parent=6" type: "post", datatype: 'json', //data format success:function(data) { var result = ""; var title = ""; alert(pages); for(var i=0; < data.length; i++) { var title = data[i]["pagetitle"]; //get name var content = data[i]["pagecontent"]; //get slug result += +content; title += "<span>"+title+"</span>"; } $('#pcontent').html(content); //set output element html $('#ptitle').html(title); //set output element html } }); });
i not getting output.
to grab query parameters in url, use angularjs $location provider. if url looks example.com/#/page?pages=5, can grab value 5 writing
var urlpagevalue = $location.search()["pages"];
be sure include $location , $http services in controller writing
yourmodulename.controller("awesomecontroller", ["$location", "$http", function($location, $http){ // page initialization code (like ajax call) here }])
then, szanto suggested, use $http service ajax call writing
$http({ url:"/yourapiendpoint", method: "post", data: { pages: urlpagevalue } }).success(function(response){ // handle returned data here }).error(function(){ // handle errors here })
finally, in original question, when got data sql call, manually appending spans dom. if going use angularjs, should assign response array variable , use ngrepeat directive in html instantiate template each item in array.
Comments
Post a Comment