1

What is wrong with this code?

<script type="text/javascript">
 var urlquery = location.href;
 var urlparts = urlquery.split('='); 
 var urlplan = (urlparts[1]); 
 $(document).ready(function() {
 $('#LDF a').click(function() { 
 $.ajax({
 url: 'src/ldf_dpd_list.php?search-n=urlplan',
 success: function (data) {
 $('#dpd').html(data);
 }
 });
 });
 });

Hi I am new to javascript and Ajax and trying to pass the variable urlplan, what is the correct way to pass the variable.

Sean Kinsey
38k7 gold badges55 silver badges71 bronze badges
asked Jun 28, 2010 at 6:30
1
  • 3
    Are you trying to bold that variable or is your code like that? Commented Jun 28, 2010 at 6:33

3 Answers 3

4

It looks like the following should do it:

var urlparts = urlquery.split('='); 
var urlplan = urlparts[1];
// ...
$.ajax({
 url: 'src/ldf_dpd_list.php?search-n=' + urlplan,
 success: function (data) {
 // ...
 }
});
answered Jun 28, 2010 at 6:33
Sign up to request clarification or add additional context in comments.

Comments

0
url: "src/ldf_dpd_list.php?search-n="+urlplan,

for more than one variable

url: "src/ldf_dpd_list.php?search-n="+urlplan+"&amp;xyz="+variablName,
answered Jun 28, 2010 at 6:33

Comments

0

This is a snippet from my easyXDM library

var _query = (function(){
 var query = {}, pair, search = location.search.substring(1).split("&"), i = search.length;
 while (i--) {
 pair = search[i].split("=");
 query[pair[0]] = pair[1];
 }
 return query;
}());

Use it like this

alert(_query["urlplan"]);

or

alert(_query.urlplan);
answered Jun 28, 2010 at 8:13

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.