javascript - Convert data attrs to get/post data -


how convert data attributes valid post (or get) data?

$('#nav').find('a').click(function(){     var params = $(this).data();     $.get({         type: "get",         url: "/view/",         data: params     }); }) 

i error:

post http://127.0.0.1/site1/%5bobject%20object%5d/ 404 (not found)  

you can use jquery.param(),

$('#nav').find('a').click(function(){     var params = $(this).data();     params = $.param(params);     $.ajax({         type: "get"         url: "/view/",         data: params     }); }) 

edit:

actually problem you're using $.get() method $.ajax().

$.get() doesn't accepts ajax settings object. change $.ajax() don't need use params.

jsfiddle demo


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -