1

I am trying to call a jquery script that will post data to a PHP form. Been googling this for 5h now but i cant seems to solve it on my own. The Script looks like this.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script language="JavaScript" type="text/javascript">
    function postscrape(igid, iguser, groupid) {

        alert(igid);
        $.post("scrapeadder.php", {
                instagramid: igid,
                username: iguser,
                groupid: groupid
            },
            function(data, status) {
                alert("Data: " + data + "\nStatus: " + status);
            });
    };
</script>

And my HTML/PHP code to call this function looks like:

  echo '<td><button type="button" class="btn btn-success datascraper" name="addscrape" id="addscrape" onclick="postscrape('.$row["instagram_id"].', '.$row["user_name"].', 1);">Add to Scrape</button></td>';

The error i get is: Uncaught ReferenceError: X is not defined

Where X = The iguser (which gets from $row["user_name"] If i check the HTML code on the homepage it list all the $rows correct. So my guess is i messed up in the function.

6
  • 1
    Maybe you should post the code that contains the error instead ? Commented Jun 8, 2015 at 23:46
  • I second that request Commented Jun 8, 2015 at 23:48
  • are you able to print out the $row["instagram_id"].', '.$row["user_name"] and sure that there valid Commented Jun 8, 2015 at 23:53
  • Yes, when i check the source code in my webbrowser i can see the correct values in all those variables. Commented Jun 8, 2015 at 23:53
  • 1
    Always look at the clientside code generated by the serverside. Do not debug from looking at server code when it is a JS error. Commented Jun 8, 2015 at 23:53

2 Answers 2

2

You need to put the user name in quotes.

onclick="postscrape('.$row["instagram_id"].', \''.$row["user_name"].'\', 1);"
Sign up to request clarification or add additional context in comments.

Comments

2

You didn't quote the user name. The

echo 'postscrape('.$row["user_name"].')' 

yields

postscrape(X)

...where X is undefined.

Comments

Your Answer

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.