Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Need help with some ajax code

Hi Experts,

I have some pictureFiles in Formdata.

formData.append('file', file);

Open in new window


How can I send that data to WebForm1.aspx/SendData and read those files? This is my Ajax code.

jQuery.ajax({
        url: 'WebForm1.aspx/SendData',
        type: 'POST',
        data: formData,
        contentType: false,
        processData: false,
        success: function (data) {
            alert("Data Added Successfully");
        },
        error: function () {
            alert("Error while inserting data");
        }
    });

Open in new window


This is my .CS code. Right now when I give a debug point it is not going to SendData for some reason.

[WebMethod]
        public static string SendData()
        {
         // code
            return "Testing!";
        }

Open in new window

 Please help! Thanks in advance!

Avatar of ste5an
ste5an
Flag of Germany image

You need to implement a standard file upload with your secret stack. These are documented very well. E.g.

Upload files in ASP.NET Core
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Thank you for trying to help me! But I am not using Core. I want to send the formData to a simple method in a .aspx file.
ASKER CERTIFIED SOLUTION
Avatar of Jonathan D.
Jonathan D.
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much for your time and trying to help me! Actually I am not using MVC. That is why I am just trying to call WebForm1.aspx/SendData.
 [WebMethod]
        public string SendData(string param)
        {
            return ("Done!");
         }

Open in new window

Also I did all the changes you recommended. I changed the data to some dummy data just to test if I can debug. But after these changes I get ERROR 500 Internal server error.
jQuery.ajax({
        type: 'GET',
        url: 'WebForm1.aspx/SendData',
        data: JSON.stringify({ param: 1}),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            alert(response.d);
        },
        failure: function (response) {
            alert(response.d);
        }
    });

Open in new window

But I am not using Core. Actually I am not using MVC.
This is not quiz show. How do you think we should help, when you don't give us the necessary information?

But my answer from above is still correct:

You need to implement a standard file upload with your secret stack. These are documented very well.

Just look up in the documentation of it, how to implement it.
Hi ste5an ,
I have provided whatever info I have. When it says WebForm1.aspx/SendData, clearly it is not MVC. Also it is very clear in my question that I need help with data transfer using Ajax "How can I send that data to WebForm1.aspx/SendData and read those files? This is my Ajax code".

Thank you for your time but your solution is not helpful to me.
You only state what its not. You don't have given a proper description of what it is. And you did not post a concise and complete example of the relevant part, which is the back end code.

Thank you for your time but your solution is not helpful to me.
Sorry, but you did not get the point: your descriptions are lacking the mandatory information to help you. And this is - I think I can speak for us  voluntary helpers here - not enough as you may have already deduced from the other threads, where others tried to help you. But failed due to this information lack.

The only things which are clear right now are:

- You have a working UI to drag'n'drop multiple files.
- This UI does the upload by a standard single file upload call.

Now the thing which matters is:

How the f looks your file upload handling code? The entire code, not a random sample.

And: Whatever project template and stack you have chosen - AND NO, IT IS NOT CLEAR RIGHT NOW WHICH IT COULD - read the MSFT documentation for it. All different project templates have the proper documentation in the MSDN and on ASP.NET.

Cause for the above UI, you only need the simple, standard single file upload of this project template/type.