0

I just stuck on some problem with my code. Could anybody please tell me what i have done wrong?

html:

<button type="button" id="searchbutton">Click Me!</button> 
<div id="resultsdiv"></div>

js:

$(document).ready(function() {

    $("#searchbutton").bind('click', function() {
        $("#resultsdiv").load(
            'http://profithing.com/wp-content/php/sorting.php',
            { // parameters, in object literal format
               sortDir: 'asc',
               sortCol: 'name'
               // etc.
            }
    });

}); 

php:

<?php
mysql_connect("localhost", "login", "pass") or die(mysql_error());
mysql_select_db("database");

$result = mysql_query("SELECT * FROM table ORDER BY added ASC");

while($row = mysql_fetch_array($result))
  {
  echo "<div class='something'>";
  echo "<a href='$row[link]'>";
  echo "<img src='$row[img]' height='125' width='125'/>";
  echo "<p>$row[name]</p></a></div>";
  echo "<br>";
  }
?> 

jsFiddle is here
i think that my php is ok, there must be some problem in calling it.
Thanks for help.

EDIT: added php code

ProfiThing
  • 19
  • 5

2 Answers2

0

You forgot a ); after your load:

$(document).ready(function() {

    $("#searchbutton").bind('click', function() {
        $("#resultsdiv").load(
            'http://profithing.com/wp-content/php/sorting.php',
            { // parameters, in object literal format
               sortDir: 'asc',
               sortCol: 'name'
               // etc.
            }); // you forgot the ); here.
    });

}); 

also the fiddle wont work because of the same origin policy... Ways to circumvent the same-origin policy

Community
  • 1
  • 1
John Boker
  • 82,559
  • 17
  • 97
  • 130
0

You're closing your statements incorrectly (missing a );). Please see below.

$(document).ready(function() {
    $("#searchbutton").bind('click', function() {
        $("#resultsdiv").load(
            'http://profithing.com/wp-content/php/sorting.php',
            { // parameters, in object literal format
               sortDir: 'asc',
               sortCol: 'name'
               // etc.
            }
        );
    });
});
dev
  • 3,969
  • 3
  • 24
  • 36
  • ok it works. one more question. do you know how that sortDir and sortCol works? thanks for help – ProfiThing Feb 25 '13 at 21:09
  • No problem... sorry no I don't.. I've had a quick search but I can't find any reference to `sortDir` and `sortCol`... can I ask where you have found this? – dev Feb 25 '13 at 21:16
  • sure. it was advice from this topic: http://stackoverflow.com/questions/15073643/how-to-call-php-into-wordpress-page-ajax – ProfiThing Feb 25 '13 at 21:33
  • ok I'm not too sure what @PatrickM is talking about here. So it may be worth replying to his comment to ask for further help. – dev Feb 25 '13 at 21:42