开发者

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 visib开发者_开发百科le 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">


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 + '\')'


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜