Click here to Skip to main content
14,391,463 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi guys

I have problem how to send data from Jquery to asp service

always give me an error

Failed to load resource: the server responded with a status of 500 (Internal Server Error) in Console


this is the code

var Info = $("#basketInfo").val();
var text = "some thing";
$.ajax({
                    url: 'Services/WebServiceAjax.asmx/InsertMethod',
                    type: 'POST',
                    dataType:"json",
                    contentType: "application/json; charset=utf-8",
                    
                    data: JSON.stringify({
                        "Items": text,
                        "BasketInfo": Info
                    }),// "{'Items':'" + text + "','basketInfo':'" + basketInfo + "'}",
                    //data: "{'Items':'" + text + "','basketInfo':'" + basketInfo + "'}",// "{'Items':'" + text + "','basketInfo':'" + basketInfo + "'}",
                    //async: false,
                    success: function (response) {
                        alert("Record Has been Saved in Database");
                    },
                    error: function (xhr, ajaxOption, thrownError)
                    { alert(thrownError); console.log('there is some error'); }
                });


and Service
[WebMethod]
   public static string InsertMethod(string Items, string BasketInfo)
   {
       try
       {
           string[] alldata = Items.Split(',');
           string[] baskInfo = BasketInfo.Split(',');
           foreach (var item in alldata)
           {
               string[] Allitems = item.Split('_');
               string itemValue = Allitems[0];
               string itemID = Allitems[1];

               Database Db = new Database();
               string CycleDesignID = Db.CustomeQuery("select CycleDesignID from CycleDesign order by CycleDesignID desc ")[0][0].ToString();
               Db.CustomInsertData(new Processes.Baskets(baskInfo[0], baskInfo[1], Convert.ToInt32(CycleDesignID), Convert.ToInt32("1")));
               string BasketID = Db.CustomeQuery("select BasketID from Baskets order by BasketID desc ")[0][0].ToString();
               Db.CustomInsertData(new Processes.BasketDetails(Convert.ToInt32(BasketID),
                   Convert.ToInt32(itemID), Convert.ToDouble(itemValue), Convert.ToDouble("3"), Convert.ToInt32("1")));
           }
       }
       catch (Exception ex)
       {
           return ex.Message;
       }
       return "Ok";
   }
Posted
Updated 20-Sep-15 23:09pm
v6
Comments
Thanks7872 21-Sep-15 3:31am
   
basketInfo != BasketInfo
Ammar Al-hamdabni 21-Sep-15 3:38am
   
sorry i didn't understand
Thanks7872 21-Sep-15 3:52am
   
You should take into consideration that parameters in web method are case sensitive.basketInfo != BasketInfo.
Ammar Al-hamdabni 21-Sep-15 4:00am
   
I changed basketInfo to Info, but doesn't work
Naveen.Sanagasetti 21-Sep-15 3:44am
   
I request you to please search the URL in browser, if it is working fine, then please check the parameters which you passed through Json call, I guess this is case sensitive, as Point out by Rohan Leuva, in method declaration you are using the parameter "BasketInfo" and in JSON call you call like below "basketInfo", I guess this might be problem, Please check this once.
Ammar Al-hamdabni 21-Sep-15 3:56am
   
it doesn't appear in URL
Naveen.Sanagasetti 21-Sep-15 4:07am
   
Call the Service URL and open the method which you try to call using JSON.
Ammar Al-hamdabni 21-Sep-15 4:14am
   
the mothod which I made it didn't appear in service
Naveen.Sanagasetti 21-Sep-15 5:23am
   
That is the reason it is throwing that error, As per Solution 1 if you remove static it will show that method in service call, obviously it should work as you expected.
digimanus 21-Sep-15 4:28am
   
see your webserver errorlog or database errorlog for the cause of this HTTP 500 error

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Remove the "static" from
public static string InsertMethod(string Items, string BasketInfo)
   
v2
Comments
Ammar Al-hamdabni 21-Sep-15 5:00am
   
You are right, It appear now, but still give me error to insert data
vagelis1 21-Sep-15 5:01am
   
please post your error message
vagelis1 21-Sep-15 5:25am
   
in your question you set
Items= "some thing"
on server side you do
string[] Allitems = item.Split('_');
string itemValue = Allitems[0];
string itemID = Allitems[1];

SO Allitems[1] will throw indexoutofrange exception as item.Split('_') will return only one element in Allitems
Ammar Al-hamdabni 21-Sep-15 6:15am
   
sorry, I mean in 'Some thing' there is a value that give me from another page.

the error always show me this message:
'Failed to load resource: the server responded with a status of 500 (Internal Server Error)'

vagelis1 21-Sep-15 6:32am
   
You should try debuging InsertMethod on the server side. Something raises exception there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100