In my Chrome Extension I’m able to get to my ‘punch.php’ file and receive data back, the problem is that I don’t seem to be able to pass data to the file. Here’s my code:
jQuery.fn.punch = function(){
$(this).click(function(){
var punchBtn = $(this);
var ProjectMemberId = '1'
var ProjectId = '1'
var str = 'ProjectMemberId='+ProjectMemberId+'&ProjectId='+ProjectId;
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://www.ontimepunchcard.com/scripts/punch.php", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
$('#PunchBox').html(xhr.responseText);
if(xhr.responseText==0)
{
punchBtn.removeClass('PunchedIn');
}
else
{
punchBtn.addClass('PunchedIn');
}
}
}
xhr.send('ProjectMemberId='+ProjectMemberId+'&ProjectId='+ProjectId);
});
}//END PUNCH METHOD
This is a duplication of a normal web application with all of the same code. The Id’s post to ‘punch.php’ and are a part of an SQL statement. The statement was failing with the Chrome extension, and returning an error statement, so I began echoing out the actual SQL query to see what it was trying to do. The result was the SQL query with the two Id’s missing, hence the error and failed query.
Do I have a syntax problem here? Is it possible that though I have the permissions set the way Google says I should, that my extension can only receive data and not send? Is there some other foolishness going on here?
“Are you sure you have proper permissions in your extensions to post data to that file? I just did a simple snippet that I return “1” from responseText. As far as I can see, the snippet is good, as long as it runs in the extension page (not the content script) – Mohamed Mansour Jan 9 at 23:45″
Apparently this is the answer.