javascript - jQuery-Ajax: Append data in URL -


i'm working ajax using jquery , want append data on url. here's sample code:

var my_site= mysamplesite.com/viewdata/"; function showdata(mydata) {     $.ajax({         type: "get",         url: my_site+"getdata"         data:{             mydata: mydata         },         datatype: "json",          success: function(data_details){             $('#data-target').html(data_details.data1+ "\n" +data_details.data2+ "\n" +data_details.data3);         }     }) } 

these function works smoothly but, i've observed url doesn't change (the data doesn't append url) whenever these function called. so, want these data appended url whenever function called. example, if value of data 1222345, want url this:

mysamplesite.com/viewdata/getdata?mydata=1222345 

in data appended url. appreciated. thanks

the easiest solution append url parameter manually instead of using data parameter of ajax call.

var my_site= "mysamplesite.com/viewdata/"; function showdata(mydata) {     $.ajax({         type: "get",         url: my_site + "getdata?mydata=" + mydata;         success: function(data_details){             $('#data-target').html(data_details.data1+ "\n" +data_details.data2+ "\n" +data_details.data3);         }     }) } 

if need through data parameter think json object must formatted this: data:{ "mydata": mydata } (note added quotes).


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -