ajax send parameter to jsp but failed - ajax

I am trying to send data to my jsp via:"xhr.send(projectCode);"
but apparently the parameter is not received when I am trying to realise it with System.out.print it is a null displayed.
so the story from the begining. my javascript function send the parameter to the jsp whitch construct an xml file and resend to the first one.
this will reconstruct my second dropdownList with the xml code constructed and received.
so the problem that the parameter dosent sent at all.
What should I do.

Just note in case the syntax whatever you have sent is like this:
url="postjob2.jsp?param=" + param;
After param=" keep a space and then the parameter. My issue got resolved as soon as I entered the space.

The simplest all-round solution is to run your application with a HTTP-tracer, such as fiddler for windows or wireshark. In that way you can see if the proper data is being submitted from your client to the server Given the amount of details you provide, I think this is the best starting point

Related

Ajax Post data lost if input length is big

I work an a Sylius project.
In the sylius_shop_ajax_cart_add_item form I added a custom input of type hidden where I send a base64 image.
The problem is that if the input is big the POST data is lost.
The ajax call is made via Semantic UI js API.
Here is the request with some small input data. The field to pay attention is image_base64.
And here is the expected result on the server, debugger stopped at the first line of the controller.
Here is the image of the html with image_base64 input
And here is the debugger right on the first line of the controller.
I use the built in server from Symfony.
My php config for max_post_size is 8mb.
Please someone any suggestion where is the problem?

Invalid postback or callback argument error in JMETER

I recorded a .net application using JMETER. After correlating and playing back it throws the below error. I have seen few posts which says eventvalidation has to be set false. Is there any other way to get rid of this error in Jmeter?
505|error|500|Invalid postback or callback argument.
Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%# Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
I guess that you're either missing or passing incorrect ASP.NET Viewstate
Basically it's an input of "hidden" type which is required to store application state and some service data which you application is expecting.
My understanding is that you're either using kind of hard-coded or recorded viewstate value or totally missing it.
I recommend to append Regular Expression Extractor Post Processor (or any suitable kind of post-processors line Beanshell, BSF, XPath - if your application talks XHTML) to extract viewstate value from each request, store it in a variable and add it to every next request.
You need to disable event validation in the config
If the dynamic DropDownList in your page, you can try to set blank to the value of DropDownList in JMeter post data. I think this problem can be solved.

Client side to server side calls

I want to change the list of available values in a dropdown depending on the value selected in another dropdown and depending on values of certain fields in the model. I want to use JQuery to do this. The only hard part is checking the values in the model. I have been informed that I can do this using Ajax. Does anyone have any idea how I will approach doing this?
AJAX is indeed the technology your looking for. It is used to sent an asynchronous request from the client browser to the server.
jQuery has an ajax function that you can use to start such a request. In your controller you can have a regular method tagged with the [HttpPostAttribute] to respond to your AJAX request.
Most of the time you will return a JSON result from your Controller to your view. Think of JSON as something similar to XML but easier to work with from a browser. The browser will receive the JSON and can then parse the results to do something like showing a message or replacing some HTML in the browser.
Here you can find a nice example of how to use it all together.

Validation - Do I need to show what is not validated in PHP if I use JS?

Okey, this might seem a bit strange question so I will explain.
Do I really need to create a postback that explains what is wrong with form if it's not validated if I also use JS for it?
I am of course validating user input and I use somewhat "general" approach. For instance if something is not validated it will just show "Some error occurred, check your input bla bla..". I am not creating postback for every input so that it will shot "Your username is suppose to be at least 3 characters long etc.." and I don't do this because JS is doing that on the fly.
My server-side validation only is like a guard against stupid/wrong entries where name is empty or something along that, rest is up to jQuery. Form will always be valid if client is running JS. I am doing it to save my time.
My question is - is it a bad idea? I just don't see why because everyone is running JS anyway and my server is not allowing bad/invalid entries to be put in DB even with JS off.
I don't think that's a bad idea, data validation can be client side. If something goes wrong, i just throw a generic error.
I only validate server side the business rules

GET vs POST in AJAX?

Why are there GET and POST requests in AJAX as it does not affect page URL anyway? What difference does it make by passing sensitive data over GET in AJAX as the data is not getting reflected to page URL?
You should use the proper HTTP verb according to what you require from your web service.
When dealing with a Collection URI like: http://example.com/resources/
GET: List the members of the collection, complete with their member URIs for further navigation. For example, list all the cars for sale.
PUT: Meaning defined as "replace the entire collection with another collection".
POST: Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is usually included as part of the data returned by this operation.
DELETE: Meaning defined as "delete the entire collection".
When dealing with a Member URI like: http://example.com/resources/7HOU57Y
GET: Retrieve a representation of the addressed member of the collection expressed in an appropriate MIME type.
PUT: Update the addressed member of the collection or create it with the specified ID.
POST: Treats the addressed member as a collection in its own right and creates a new subordinate of it.
DELETE: Delete the addressed member of the collection.
Source: Wikipedia
Well, as for GET, you still have the url length limitation. Other than that, it is quite conceivable that the server treats POST and GET requests differently; thus the need to be able to specify what request you're doing.
Another difference between GET and POST is the way caching is handled in browsers. POST response is never cached. GET may or may not be cached based on the caching rules specified in your response headers.
Two primary reasons for having them:
GET requests have some pretty restrictive limitations on size; POST are typically capable of containing much more information.
The backend may be expecting GET or POST, depending on how it's designed. We need the flexibility of doing a GET if the backend expects one, or a POST if that's what it's expecting.
It's simply down to respecting the rules of the http protocol.
Get - calls must be idempotent. This means that if you call it multiple times you will get the same result. It is not intended to change the underlying data. You might use this for a search box etc.
Post - calls are NOT idempotent. It is allowed to make a change to the underlying data, so might be used in a create method. If you call it multiple times you will create multiple entries.
You normally send parameters to the AJAX script, it returns data based on these parameters. It works just like a form that has method="get" or method="post". When using the GET method, the parameters are passed in the query string. When using POST method, the parameters are sent in the post body.
Generally, if your parameters have very few characters and do not contain sensitive information then you send them via GET method. Sensitive data (e.g. password) or long text (e.g. an 8000 character long bio of a person) are better sent via POST method.
Thanks..
I mainly use the GET method with Ajax and I haven't got any problems until now except the following:
Internet Explorer (unlike Firefox and Google Chrome) cache GET calling if using the same GET values.
So, using some interval with Ajax GET can show the same results unless you change URL with irrelevant random number usage for each Ajax GET.
Others have covered the main points (context/idempotency, and size), but i'll add another: encryption. If you are using SSL and want to encrypt your input args, you need to use POST.
When we use the GET method in Ajax, only the content of the value of the field is sent, not the format in which the content is. For example, content in the text area is just added in the URL in case of the GET method (without a new line character). That is not the case in the POST method.

Resources