AJAX Question - Newbie - ajax

I have a HTML TEXT BOX in one of my webpage, there is not submit button.
<form>
<label>Website URL: </label>
<input name="" type="text" class="textfield" />
</form>
The text box is used to enter url, i need to do validation of this textbox using AJAX.So for example if someone enters url and hit enter the URL will appear below the text box and the text box will be emptied again. It will only do this if it is a validly formed url, for example if someone writes ttjkl.145 this will not do anything as it is not a valid url. It will however accept any variations that are valid such as http://www.url.com or www.url.co.uk and url.com.au. And it will remove anything after the end of the country code for example if the person types www.abc.net/dlkjfk then only www.abc.net will be accepted

What you need has nothing to do with Ajax. JavaScript alone can do what you need.
The answer you seek already exists:
URL regex validation
Help me validate url which should even accept .me domains
how can i validate a url in javascript using regular expression

Related

How to enter a text in textbox (which makes AJAX calls) using JMeter?

Help me with the steps to follow to enter a simple text into input box which contains AJAX calls as below using Jmeter.
input name="investTrade:counterParty" id="investTrade:counterParty"
style="text-transform: uppercase;"
onchange="A4J.AJAX.Submit('_viewRoot','investTrade',event,{'control':this,'ignoreDupResponses':true,'status':'false','similarityGroupingId':'investTrade:j_id822','parameters':{'investTrade:j_id822':'investTrade:j_id822','ajaxSingle':'investTrade:counterParty'} ,'eventsQueue':'serialQueue','actionUrl':'/App/InvestTradeEdit.seam'}
)" type="text" size="6" maxlength="6
When I am trying to enter text such as "XYZ" in the textbox, the HTML content change as shown below:
input name="investTrade:counterParty" id="investTrade:counterParty"
style="text-transform: uppercase;"
onchange="A4J.AJAX.Submit('_viewRoot','investTrade',event,{'control':this,'ignoreDupResponses':true,'status':'false','similarityGroupingId':'investTrade:j_id822','parameters':{'investTrade:j_id822':'investTrade:j_id822','ajaxSingle':'investTrade:counterParty'} ,'eventsQueue':'serialQueue','actionUrl':'/App/InvestTradeEdit.seam'}
)" type="text" size="6" maxlength="6" value="XYZ" autocomplete="off">
The problem I am facing in JMeter, I have recorded user actions through HTTP(s) Test Script Recorder. All the user actions is properly recorded under Recording Controller. But when I am trying to run the recorded actions, I couldn't find the text entered in Response Data(View Result Tree). Dynamic values ($variable) passed under parameter section is not getting entered in textbox nor getting displayed.
What should I do after recording user actions? How to handle ajax calls in jmeter [please let me know clearly I have seen previous post related to this]? We are using seam framework with more AJAX functionality. Guide me friends! thanks :)

Radbutton Onclick mozilla bug

When i click a radbutton then postback changing page url as /blabla.aspx?btnMsg_ClientState=&btnCarDetails=Sorgula&btnCarDetails_ClientState=&btnPrice_ClientState=&btnReject_ClientState=# ..
First pop-up work but then break.
There are 5 extra buttons and seems all in page url. Where is coming these query strings ?
Ie Developer tools says:
ScriptResource.axd...
I cant find solution, please help.
It appears that the form on your page is configured to use a GET request when submitted.
<form id="form1" runat="server" method="get">
In this case all parameters on the page are specified as part of the URL, which includes the input elements that are used for rendering the button, as well as the other input elements on your page.
You can change this behavior by setting the method attribute of the form to post, so that a POST request is utilized for submitting the form.
<form id="form1" runat="server" method="post">
In this case the parameters will be passed in the message body of the HTTP request.

Refresh Captcha Image on JQUERY Dialog

I've a jquery model dialg box below. When user clicks on one of the link on page, the dialog box appears with Captcha. When user enters the invalid captch the captch image should be refreshed and should show new text. But this is not happening. Below is the code snippet:
<div id="model">
<img id="captchaImage" src="#Url.Content("~/CaptchaImage.ashx?text=" + ViewBag.EncryptedCaptcha)" />
<input id="captchText" type="text" value="" />
Validate
</div>
When user clicks on Validate, the text is sent to MVC controller via $.getJSON. The controller returns back isCpatchValid and encryptedText wrapped in JSON object Captcha. I've a done below if
the captcha text is not valid:
$("#captchaImage").attr("src", "~/CaptchaImage.ashx?text=" +
Captcha.encryptedText);
On Chrome debugger I can see the controller is returning a correct encrypted text. But this line above doesn't deem to fresh the captch image. I suspect this is due to async call.
COuld someone please help me with how to refresh the captcha image on Jauery Dialog box.
You can't use the "~" feature in javascript. That's a .NET thing. You'll need to wrap it around a .NET call, like:
attr("src", "#Url.Content("~/CaptchaImage.ashx")?text=" + Captcha.encryptedText)
Or if this JS is in a separate file, you can define a variable back on the view, then use it in the JS file, like:
** in the view **
var CAPTCHA_IMAGE_URL = "#Url.Content("~/CaptchaImage.ashx")";
** in the JS file **
attr("src", CAPTCHA_IMAGE_URL + "?text=" + Captcha.encryptedText)

How to recognaize which ajax form it is in Django?

I have view which takes care of all the Ajax submits from the client side. And to differentiate them by I uses different submit button names such as this one
<input type="submit" value="Send" name="send_message">
Suggested from this question.
The only problem is that from the view side it doesn't seems to carry the name to the server side so I cannot use the following if-statement
if 'send_message' in request.POST:
It works if I send it normally with page fresh. But I want to use it with Ajax.
I came up with a hack that you can add this name with jQuery. Simply by after serializing() your data you then concatenate the name attribute by data += "&send_message"
Then the if statement will work. But it doesn't seems so clean. So I wonder if there's a better way to handle this? Or should I make different views to handle the different Ajax calls I have?
You really should post each form to a different URL.
If not, you could add a hidden input with the name of the form as the value.
<input name="form_name" type="hidden" value="form_1" />
views.py:
form_name = request.POST['form_name']

ci_csrf_token was set to ” onmouseover=prompt(XSS) bad=”

i used ci_csrf_token hidden field in my forms.but any form in my script get alert with Acunetix Web Vulnerability Scanner.
alert details :
Cookie input ci_csrf_token was set to " onmouseover=prompt(965267) bad="
The input is reflected inside a tag element between double quotes.
in view source:
<input type="hidden" name="ci_csrf_token" value="\\" onmouseover=prompt(965267) bad=\"" />
can anyone help me to solve it?
You need to html attribute encode the token before you put it into the hidden field. Do you add it to the form on the client side or the server side? If you do it on the server side, you may want to do input validation to make sure the token is on the expected format.

Resources