Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-10
2
Medium Priority
?
2,582 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

618 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