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.
-
1Maybe you should post the code that contains the error instead ?adeneo– adeneo2015年06月08日 23:46:36 +00:00Commented Jun 8, 2015 at 23:46
-
I second that requestM H– M H2015年06月08日 23:48:50 +00:00Commented Jun 8, 2015 at 23:48
-
are you able to print out the $row["instagram_id"].', '.$row["user_name"] and sure that there validShapCyber– ShapCyber2015年06月08日 23:53:02 +00:00Commented 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.Zara Rebecka Elisabeth Zentio– Zara Rebecka Elisabeth Zentio2015年06月08日 23:53:39 +00:00Commented Jun 8, 2015 at 23:53
-
1Always look at the clientside code generated by the serverside. Do not debug from looking at server code when it is a JS error.epascarello– epascarello2015年06月08日 23:53:41 +00:00Commented Jun 8, 2015 at 23:53
2 Answers 2
You need to put the user name in quotes.
onclick="postscrape('.$row["instagram_id"].', \''.$row["user_name"].'\', 1);"
Comments
You didn't quote the user name. The
echo 'postscrape('.$row["user_name"].')'
yields
postscrape(X)
...where X is undefined.
Comments
Explore related questions
See similar questions with these tags.