[jQuery] Re: Safe Ajax Calls?
Thanks, the idea would be like this: $(document).ready(function(){ $('a.aj_link').click(function(){ var link=$(this).attr("href"); link = link.split('?'); var url = link[0]; var sendVars = link[1]; var layer = $(this).attr("name"); $.ajax({ type: "POST", url: "ajax/"+url+".asp?nocache="+Math.random(), data: sendVars, success: function(msg){ $('#'+layer).html(msg); }, dataType: 'HTML' }); return false; }); }); This script is in a .js file I took the href attribute as de main query string, then de first part of the string is the url and the rest is the dataString And the name attribute represents the id of the element to inject with HTML But here is another question, what if I need to get a json data type? Ok, maybe i should do another onClick event for other class of link but, how can I read this data in a function after the success event, any ideas? Greetings! On 11 feb, 15:58, Ricardo Tomasi wrote: > *and don't forget to return false or do e.preventDefault() > > $('.aj-link').click(function(){ > var page = $(this).attr('href'); > $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); > return false; > > }); > > On Feb 11, 4:57 pm, Ricardo Tomasi wrote: > > > $('.aj-link').click(function(){ > > var page = $(this).attr('href'); > > $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); > > > }); > > >http://docs.jquery.com/Selectorshttp://docs.jquery.com/Eventshttp://d... > > > On Feb 11, 10:40 am, SoulRush wrote: > > > > I though that it would be nice to make the links with a certain format > > > like: > > > > link > > > > And make a selection for that kind of links with jquery, that takes > > > these data to make an ajax call with post... > > > > That selection should be in a .js outside of the source of the pages > > > and packed or something... > > > > What do you think? > > > > Please I need some feedback :) > > > Greetings! > > > > On 9 feb, 17:02, SoulRush wrote: > > > > > By the way, the first parameter takes the vars to send... so in the > > > > pages I've to dynamically set varname1=value1&varname2=value2 > > > > > On 9 feb, 10:40, SoulRush wrote: > > > > > > Hi! > > > > > > I'm kind of new at the world of ajax and jquery and i'm starting to > > > > > make a site with them. > > > > > > In my site i've created a single function (in the header) called > > > > > ajaxQry(...) which takes some parameters like, url to make post or > > > > > get, if I need GEt or POST, the data type of the query, a success > > > > > function and an error function. > > > > > > Anyway, it look like this: > > > > > > function ajaxQry(sendVars, url, returnType, backFunction, > > > > > errorFunction){ > > > > > > $.ajax({ > > > > > type: "POST", > > > > > url: "ajax/"+url+".asp?nocache="+Math.random(), > > > > > data: sendVars, > > > > > success: backFunction, //ussully this loads the content in > > > > > the main > > > > > page as html > > > > > dataType: returnType, > > > > > error: errorFunction > > > > > }); > > > > > > } > > > > > > Everything works great but i don't know if there's a better way to do > > > > > this, because in many events of the site I call this function... And > > > > > I'm starting to think that it's pretty insecure What do you think? > > > > > > By the way i ussually call the url file (see the function) and return > > > > > HTML content, and then i load it in the page with $(selector).html(); > > > > > is that okay? > > > > > > Thanks! and sorry for my english :$
[jQuery] Re: Safe Ajax Calls?
$('.aj-link').click(function(){ var page = $(this).attr('href'); $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); }); http://docs.jquery.com/Selectors http://docs.jquery.com/Events http://docs.jquery.com/Ajax On Feb 11, 10:40 am, SoulRush wrote: > I though that it would be nice to make the links with a certain format > like: > > link > > And make a selection for that kind of links with jquery, that takes > these data to make an ajax call with post... > > That selection should be in a .js outside of the source of the pages > and packed or something... > > What do you think? > > Please I need some feedback :) > Greetings! > > On 9 feb, 17:02, SoulRush wrote: > > > By the way, the first parameter takes the vars to send... so in the > > pages I've to dynamically set varname1=value1&varname2=value2 > > > On 9 feb, 10:40, SoulRush wrote: > > > > Hi! > > > > I'm kind of new at the world of ajax and jquery and i'm starting to > > > make a site with them. > > > > In my site i've created a single function (in the header) called > > > ajaxQry(...) which takes some parameters like, url to make post or > > > get, if I need GEt or POST, the data type of the query, a success > > > function and an error function. > > > > Anyway, it look like this: > > > > function ajaxQry(sendVars, url, returnType, backFunction, > > > errorFunction){ > > > > $.ajax({ > > > type: "POST", > > > url: "ajax/"+url+".asp?nocache="+Math.random(), > > > data: sendVars, > > > success: backFunction, //ussully this loads the content in the > > > main > > > page as html > > > dataType: returnType, > > > error: errorFunction > > > }); > > > > } > > > > Everything works great but i don't know if there's a better way to do > > > this, because in many events of the site I call this function... And > > > I'm starting to think that it's pretty insecure What do you think? > > > > By the way i ussually call the url file (see the function) and return > > > HTML content, and then i load it in the page with $(selector).html(); > > > is that okay? > > > > Thanks! and sorry for my english :$
[jQuery] Re: Safe Ajax Calls?
*and don't forget to return false or do e.preventDefault() $('.aj-link').click(function(){ var page = $(this).attr('href'); $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); return false; }); On Feb 11, 4:57 pm, Ricardo Tomasi wrote: > $('.aj-link').click(function(){ > var page = $(this).attr('href'); > $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); > > }); > > http://docs.jquery.com/Selectorshttp://docs.jquery.com/Eventshttp://docs.jquery.com/Ajax > > On Feb 11, 10:40 am, SoulRush wrote: > > > I though that it would be nice to make the links with a certain format > > like: > > > link > > > And make a selection for that kind of links with jquery, that takes > > these data to make an ajax call with post... > > > That selection should be in a .js outside of the source of the pages > > and packed or something... > > > What do you think? > > > Please I need some feedback :) > > Greetings! > > > On 9 feb, 17:02, SoulRush wrote: > > > > By the way, the first parameter takes the vars to send... so in the > > > pages I've to dynamically set varname1=value1&varname2=value2 > > > > On 9 feb, 10:40, SoulRush wrote: > > > > > Hi! > > > > > I'm kind of new at the world of ajax and jquery and i'm starting to > > > > make a site with them. > > > > > In my site i've created a single function (in the header) called > > > > ajaxQry(...) which takes some parameters like, url to make post or > > > > get, if I need GEt or POST, the data type of the query, a success > > > > function and an error function. > > > > > Anyway, it look like this: > > > > > function ajaxQry(sendVars, url, returnType, backFunction, > > > > errorFunction){ > > > > > $.ajax({ > > > > type: "POST", > > > > url: "ajax/"+url+".asp?nocache="+Math.random(), > > > > data: sendVars, > > > > success: backFunction, //ussully this loads the content in > > > > the main > > > > page as html > > > > dataType: returnType, > > > > error: errorFunction > > > > }); > > > > > } > > > > > Everything works great but i don't know if there's a better way to do > > > > this, because in many events of the site I call this function... And > > > > I'm starting to think that it's pretty insecure What do you think? > > > > > By the way i ussually call the url file (see the function) and return > > > > HTML content, and then i load it in the page with $(selector).html(); > > > > is that okay? > > > > > Thanks! and sorry for my english :$
[jQuery] Re: Safe Ajax Calls?
I though that it would be nice to make the links with a certain format like: link And make a selection for that kind of links with jquery, that takes these data to make an ajax call with post... That selection should be in a .js outside of the source of the pages and packed or something... What do you think? Please I need some feedback :) Greetings! On 9 feb, 17:02, SoulRush wrote: > By the way, the first parameter takes the vars to send... so in the > pages I've to dynamically set varname1=value1&varname2=value2 > > On 9 feb, 10:40, SoulRush wrote: > > > Hi! > > > I'm kind of new at the world of ajax and jquery and i'm starting to > > make a site with them. > > > In my site i've created a single function (in the header) called > > ajaxQry(...) which takes some parameters like, url to make post or > > get, if I need GEt or POST, the data type of the query, a success > > function and an error function. > > > Anyway, it look like this: > > > function ajaxQry(sendVars, url, returnType, backFunction, > > errorFunction){ > > > $.ajax({ > > type: "POST", > > url: "ajax/"+url+".asp?nocache="+Math.random(), > > data: sendVars, > > success: backFunction, //ussully this loads the content in the > > main > > page as html > > dataType: returnType, > > error: errorFunction > > }); > > > } > > > Everything works great but i don't know if there's a better way to do > > this, because in many events of the site I call this function... And > > I'm starting to think that it's pretty insecure What do you think? > > > By the way i ussually call the url file (see the function) and return > > HTML content, and then i load it in the page with $(selector).html(); > > is that okay? > > > Thanks! and sorry for my english :$
[jQuery] Re: Safe Ajax Calls?
By the way, the first parameter takes the vars to send... so in the pages I've to dynamically set varname1=value1&varname2=value2 On 9 feb, 10:40, SoulRush wrote: > Hi! > > I'm kind of new at the world of ajax and jquery and i'm starting to > make a site with them. > > In my site i've created a single function (in the header) called > ajaxQry(...) which takes some parameters like, url to make post or > get, if I need GEt or POST, the data type of the query, a success > function and an error function. > > Anyway, it look like this: > > function ajaxQry(sendVars, url, returnType, backFunction, > errorFunction){ > > $.ajax({ > type: "POST", > url: "ajax/"+url+".asp?nocache="+Math.random(), > data: sendVars, > success: backFunction, //ussully this loads the content in the main > page as html > dataType: returnType, > error: errorFunction > }); > > } > > Everything works great but i don't know if there's a better way to do > this, because in many events of the site I call this function... And > I'm starting to think that it's pretty insecure What do you think? > > By the way i ussually call the url file (see the function) and return > HTML content, and then i load it in the page with $(selector).html(); > is that okay? > > Thanks! and sorry for my english :$