P.Brian.Mackey
P.Brian.Mackey

Reputation: 44285

jQuery - Why isnt my POST firing?

var htmlGeneratedContent = '<td align="right"><input type="button" value="Save Comment" class="button" onClick="' +               
'submitToServer(' + key + ',' + userID + ',' + batchID + ')' + 

The code above generates HTML visible in firebug as

<input type="button" onclick="submitToServer(1111,bmackey,2222);deActivateThat();" class="button" value="Save Comment">

But when I click my function does not fire

    function submitToServer(key, userID, batchID) {
        $.post("savePage.aspx",//breakpoint never hit
            { key: key, userID: userID, batchID: batchID }
        );
    }

I tried wrapping my generated string to produce submitToServer('1111','bmackey','2222'). bit the code

'submitToServer(\"' + key + '\",\"' + userID + '\",\"' + batchID + '\")' + 

ended up generating the HTML wrong.

<input type="button" );deactivatethat();="" 2222="" ,="" bmackey="" 1111="" onclick="submitToServer(" class="button" value="Save Comment">

Upvotes: 0

Views: 55

Answers (2)

Talljoe
Talljoe

Reputation: 14827

My guess on the first part is that in the code submitToServer(1111,bmackey,2222); "bmackey" should be in quotes, since it's not a valid identifier. You should be receiving an error for that.

submitToServer(1111,'bmackey',2222);

Upvotes: 1

csupnig
csupnig

Reputation: 3377

you are using " when you pass the string variables to submitToServer and as the html attribute onclick is also using them, the code gets all messed up.

try to replace them with single quotes.

submitToServer(\'' + key + '\',\'' + userID + '\',\'' + batchID + '\')'

Upvotes: 1

Related Questions