How can I convert php to asp.net mvc

kerapap

New Member
I have found a really nice captcha control which is based on jquery. But they wrote a php method and I really do not have any experience in php.jquery codes: ;(function( $ ){ $.fn.captcha = function(options){ var defaults = { borderColor: "", captchaDir: "../../content/captcha", url: "captcha/captcha.php", formId: "myForm", text: "Verify that you are a human,<br />drag <span>scissors</span> into the circle.", items: Array("pencil", "scissors", "clock", "heart", "note") }; var options = $.extend(defaults, options); $(this).html("<b class='ajax-fc-rtop'><b class='ajax-fc-r1'></b> <b class='ajax-fc-r2'></b> <b class='ajax-fc-r3'></b> <b class='ajax-fc-r4'></b></b><img class='ajax-fc-border' id='ajax-fc-left' src='" + options.captchaDir + "/imgs/border-left.png' /><img class='ajax-fc-border' id='ajax-fc-right' src='" + options.captchaDir + "/imgs/border-right.png' /><div id='ajax-fc-content'><div id='ajax-fc-left'><p id='ajax-fc-task'>" + options.text + "</p><ul id='ajax-fc-task'><li class='ajax-fc-0'><img src='" + options.captchaDir + "/imgs/item-none.png' alt='' /></li><li class='ajax-fc-1'><img src='" + options.captchaDir + "/imgs/item-none.png' alt='' /></li><li class='ajax-fc-2'><img src='" + options.captchaDir + "/imgs/item-none.png' alt='' /></li><li class='ajax-fc-3'><img src='" + options.captchaDir + "/imgs/item-none.png' alt='' /></li><li class='ajax-fc-4'><img src='" + options.captchaDir + "/imgs/item-none.png' alt='' /></li></ul></div><div id='ajax-fc-right'><a target='_blank' href='http://www.webdesignbeach.com'><img id='ajax-fc-backlink' src='" + options.captchaDir + "/imgs/wdb.png' alt='Web Design Beach' /></a><p id='ajax-fc-circle'></p></div></div><div id='ajax-fc-corner-spacer'></div><b class='ajax-fc-rbottom'><b class='ajax-fc-r4'></b> <b class='ajax-fc-r3'></b> <b class='ajax-fc-r2'></b> <b class='ajax-fc-r1'></b></b>"); var rand = $.ajax({ url: options.url,async: false }).responseText; var pic = randomNumber(); $(".ajax-fc-" + rand).html( "<img src=http://stackoverflow.com/"" + options.captchaDir +"/imgs/item-" + options.items[pic] + ".png\" alt=\"\" />"); $("p#ajax-fc-task span").html(options.items[pic]); $(".ajax-fc-" + rand).addClass('ajax-fc-highlighted'); $(".ajax-fc-" + rand).draggable({ containment: '#ajax-fc-content' }); var used = Array(); for(var i=0;i<5;i++){ if(i != rand && i != pic) { $(".ajax-fc-" +i).html( "<img src=http://stackoverflow.com/"" + options.captchaDir +"/imgs/item-" + options.items + ".png\" alt=\"\" />"); used = options.items; } } $(".ajax-fc-container, .ajax-fc-rtop *, .ajax-fc-rbottom *").css("background-color", options.borderColor); $("#ajax-fc-circle").droppable({ drop: function(event, ui) { $(".ajax-fc-" + rand).draggable("disable"); $("#" + options.formId).append("<input type=\"hidden\" style=\"display: none;\" name=\"captcha\" value=http://stackoverflow.com/"" + rand + "\">"); }, tolerance: 'touch' }); };})( jQuery );function randomNumber() { var chars = "01234"; chars += "."; var size = 1; var i = 1; var ret = ""; while ( i <= size ) { $max = chars.length-1; $num = Math.floor(Math.random()*$max); $temp = chars.substr($num, 1); ret += $temp; i++; } return ret;} var rand = $.ajax({ url: options.url,async: false }).responseText;this is getting value from php method which is at following <?php/* captcha.php jQuery Fancy Captcha www.webdesignbeach.com Created by Web Design Beach. Copyright 2009 Web Design Beach. All rights reserved.*/session_start(); /* starts session to save generated random number *//* this compare captcha's number from POST and SESSION */if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['captcha']) && $_POST['captcha'] == $_SESSION['captcha']) { echo "Passed!"; /* YOUR CODE GOES HERE */ unset($_SESSION['captcha']); /* this line makes session free, we recommend you to keep it */ }elseif($_SERVER['REQUEST_METHOD'] == "POST" && !isset($_POST['captcha'])) { echo "Failed!"; }/* in case that form isn't submitted this file will create a random number and save it in session */else { $rand = rand(0,4); $_SESSION['captcha'] = $rand; echo $rand; }?>as I see, it generates a random number and save it in session, if session already has it, it sends it.here is my asp.net code public string CaptchaControl( ) { string captha=""; try { captha = HttpContext.Session["captcha"].ToString(); } catch (Exception) { Random rnd = new Random(); captha = rnd.Next(0, 5).ToString(); Session.Add("captcha", captha); } return captha; }and here is my jquery methodfunction GenerateNumber() {var numara = 0; $.ajax({ type: "post", url: '@Url.Action("JqueryOku","Home")', success: function (msg) { numara = msg; alert("captcha " + msg); }, error: function (request, status, error) { alert("Hata olu?tu: " + error + "\nHata Kodu: " + request.status); } });return numara;}normally, it works if its not in this js file. but if I put this code to that file like var rand = GenerateNumber();I get this errorPOST loclhost:8383/Account/@Url.Action(%22JqueryOku%22,%22Home%22)500 (Internal Server Error) jquery-1.5.1.js:7315send jquery-1.5.1.js:7315 jQuery.extend.ajax jquery-1.5.1.js:6776$.fn.captcha jquery.captcha.js:19 (anonymous function) Register:57deferred.resolveWith jquery-1.5.1.js:865 jQuery.extend.ready jquery-1.5.1.js:423 DOMContentLoaded jquery-1.5.1.js:1058JqueryOku method is in HomeController. I do not know where is my mistake
 
Top