?
Solved

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

Posted on 2008-06-10
2
Medium Priority
?
2,581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Pawel Witkowski earned 750 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

762 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