9three Posted August 31, 2009 Share Posted August 31, 2009 Hey, I've seen some sites that do the following: <a href="example.php" onclick="ajax_functionname(parameter)">Example</a> Which then that function calls an external file and does what it's suppose to do. I'm currently using jQuery and every example is done inline. Which means people can view the source, how it functions, what page gets requested, and most importantly it means I have to go to every page with that same function and edit it page by page. For example, in one of my pages I do this: $.ajax({ url: "test.html", cache: false, success: function(html){ $("#results").append(html); } }); I know that I could do $('.ajax').onclick(function () {...}) but it still shows what's happening. How can I accomplish using this style instead? Quote Link to comment Share on other sites More sharing options...
corbin Posted September 1, 2009 Share Posted September 1, 2009 function getPage(page) { $.ajax({ url: page, cache: false, success: function(html){ $("#results").append(html); } }); } <a href="blah.php" onclick="getPage('blah.php'); return false;">blah.php</a> Quote Link to comment Share on other sites More sharing options...
9three Posted September 1, 2009 Author Share Posted September 1, 2009 hm.. maybe that wasn't the best example. I'll use facebook.com as an example. When you click on the button "sign up" it calls an ajax function. You can't see the file it's being referenced though. Here's the link: onclick="seo_tracking_onclick(this,"facebookpoc","facebookpoc","1","1","Signup","Simple Reg Box");RegUtil.getInstance().ajax_validate_data({ignore: ['captcha']}, 'registration_container', '1' ); return false;" That's from the not logged in index page. In the html source there is no reference towards an outside file, although I know there is. It's sorta like "hidden". Quote Link to comment Share on other sites More sharing options...
9three Posted September 1, 2009 Author Share Posted September 1, 2009 Here's an even better example, from newartist.com In the head, they have: xajax_chkLogin = function() { return xajax.request( { xjxfun: 'chkLogin' }, { parameters: arguments } ); }; And in the body <input id='submit' type='button' name='submit' value='Login' class='submit-button' onclick='xajax_chkLogin(xajax.getFormValues("login"));' /> Again no reference to an external file. Quote Link to comment Share on other sites More sharing options...
corbin Posted September 1, 2009 Share Posted September 1, 2009 Here's an even better example, from newartist.com In the head, they have: xajax_chkLogin = function() { return xajax.request( { xjxfun: 'chkLogin' }, { parameters: arguments } ); }; And in the body <input id='submit' type='button' name='submit' value='Login' class='submit-button' onclick='xajax_chkLogin(xajax.getFormValues("login"));' /> Again no reference to an external file. I would imagine the xajax.request method defaults to the current file (since it makes a request to index.php). Oh, actually it's set here: xajax.config.requestURI = "http://newartist.com/index.php"; xajax.config.statusMessages = false; xajax.config.waitCursor = true; xajax.config.version = "xajax 0.5"; xajax.config.legacy = false; xajax.config.defaultMode = "asynchronous"; xajax.config.defaultMethod = "POST"; Unless you want to use some client side parsing to determine the URL you need to make a request to based on the current URL or something, there's not really a way to magically know what page to make the request to. Edit: One option could be to do it all through the same page and have different handlers. For example if handler=Something, then a function called Something could be executed (or a method of a class called Something). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.