0

<a href="#" onclick='contacts($code)'>Contact Details</a>

This runs a jquery code with the value $code. in Firebug I can see it gets the correct rowset value,
the jquery is below:

function contacts(code){
  jQuery.ajaxSetup({async:true});
  jQuery.post("php/contact.php", {code: code}, function(data) {
$('#results').hide();
$('#results').fadeIn(2000);
$('#results').show() .html(data);
});
}

it is supposed to post this value to the contact.php page, which has worked perfectly in other applications ive written using this method.

I keep getting ReferenceError: UA11 is not defined (UA11 being the rowset value) in firebug.

Cant seem to work out whats wrong?

2
Contributors
6
Replies
24
Views
3 Years
Discussion Span
Last Post by Anthony21
0

Check out a couple of things to help diagnose what is wrong. You may have already tried some of these, but just in case:

  1. Make sure that the correct value is being passed into the function - either set a breakpoint on line 2 or print the value of code. Also, if the $code variable is a PHP variable, it should be wrapped in <? ?>.

  2. Check your contact.php file thoroughly, to make it easier, pass in an expected value through a url manually (e.g. contact.php?code=14), and check it all works with $_GET['code'], you can change it back to using POST after you are sure the contact file works as expected.

  3. On that point, make sure you are retrieving code using $_POST['code'] and not $_GET['code'] when using the function.

  4. Try changing jQuery to $.

  5. Try using the ajax method instead:

    var request = $.ajax({
    url: "php/contact.php",
    type: "POST",
    data: { code : code },
    dataType: "html"
    });

    request.done(function(data) {
    $('#results').hide();
    $('#results').fadeIn(2000);
    $('#results').show() .html(data);
    });

Hope this helps!

0

Thanks, I have checked all the above to no avail, the part of my code that is supposed to post the value is here:

$alias = $row['Site_Alias'];
$alias = str_replace('_', ' ', $alias);
$hostname = $row['Hostname'];
$code = trim($hostname, '()');
$code = substr($code, 0, 4);
echo <<<EOF
<table width="100%" border=0">
<tr><td  class="grey">$status $psba - Customer - $newresult - $hostname - $alias <span class='contact'><a href="#" onclick='contacts($code)'>Contact Details</a></span></td><td class="red" rowspan="2">$street<br />$city<br /> $county, $zip</td></tr>
<tr><td class="green"> <span class='circuit'>$circuit </span><span class='bte'>$exchange</span></td></tr>
</table>
EOF;
}

it shows the correct variable, but nothing is being posted...i set a static value in contracts() and thats not being posted anywhere either.. Im lost!

0

keeps on saying its undefined.. doesnt tell what is undefined though, im sure the issue lies with the onclick and jquery... but the exact same code worked on my previous app.. most annoying!

2

I think I know what's wrong, try wrapping the $code variable in double quotes:

onclick='contacts("$code")'

Let me know if that fixes it!

0

BIG SIGH

Thankyou Anthony21 for looking at this, 2nd pair of eyes is always good!
this has solved the issue, many many thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.