Solved

Using jQuery load() function with key value pairs in query string

Posted on 2008-06-10
2
2,576 Views
Last Modified: 2009-07-29
Hi,

Am using jQuery for some AJAX work. Am using the code below to load pages:

$(document).ready(function() {
  $('a.somelink').click(function() {
    $('.maincontent').hide().load('someurl', {'term': $(this).text()});
    return false;
  });
});

and this is the url which generates the request:

<a class="somelink" href="someurl?term=<?php echo $row['name'];?>"><?php echo $row['name'];?></a>

All works fine - no problem.

However, the request which allows me to do the MySQL is generated using text(). I want to be able to retrieve the key/value pairs in the url to do some other stuff eg

<a class="somelink" href="someurl?term=<?php echo $row['name']&amp;section=<?php echo $row['section']">some link text here</a>

I am trying the grab the values of term and section ---- can anyone help?

Many thanks

Daisy
0
Comment
Question by:daisydoos
2 Comments
 
LVL 18

Accepted Solution

by:
Pawel Witkowski earned 250 total points
ID: 21757380
grab from javascript ? its simple, just use regexp like this:

function parse(text)
{
var ret={}
var temp=text.match(/\w+=\w+(?=&)|\w+=\w+$/g);
for (var temp2 in temp)
  ret[temp[temp2].match(/\w+(?==)/).toString()]=temp[temp2].match(/\w+$/).toString();
return ret;
}

var a="some page?test=1&test2=53";

alert( parse(a).toSource());
0
 

Author Comment

by:daisydoos
ID: 21757913
Hi,
Many thanks for your help - sorry, I am not up to speed on regex..

using this as the url for var a:

var a = '<a href="<?php echo $_SERVER['PHP_SELF'];?>?section=admin&page=newpage">hello</a>'

alerts this back:

($section:"admin")) only, not the $page:"newpage"..  

Also, assuming we had the key/value paird, can you tell me how I would apply this to the jQuery load function described above?

Many thanks

Daisy
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question