Solved

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

Posted on 2008-06-10
2
2,575 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:
wilq32 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now