Solved

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

Posted on 2008-06-10
2
2,579 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

732 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