Skip to main content

post data using api using jquery get | post

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>My New Page</title>
    <script  type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
   <!-- <script type="text/javascript"  src="C:\Users\31055\Downloads\openlogic-jquery-1.6.2-all-src-1\jquery-1.6.2-src\jquery-1.6.2.js"></script>-->
   <!-- <script type="text/javascript">
        $(document).ready(function () {

            alert('okay');

            debugger;

            $.ajax({
         
//             JQuery.support.cors=true;
                       //      url: 'http://rest.learncode.academy/api/will/friends',
                url: 'http://hsapirepo.azurewebsites.net/api/hs/salunkhe/moodkyahai ',
             
                type: "POST",
                dataType: "json",
                async: true,
                crossDomain: true,
                processData: false,
                contentType: false,
                data:'C:\Users\31055\Desktop\kasam.png',
                success: function (data) {
                    debugger;
                                     
                    lbl.innerHTML ='Name='+ data[0].name+'and Age='+data[0].age +'and id='+data[0].id;
                   

  $('#popupdiv').html(data[0].name.toString());
},
                error: function () {
                debugger;
                    ErrorFunction();
                }

                        });
//            $.ajax({
//        
//                async: true,
//                crossDomain: true,
//                url: 'http://hsapirepo.azurewebsites.net/api/hs/salunkhe/moodkyahai',
//                method: 'POST',
//                headers: {
//                    'cache-control': 'no-cache',
//                    'postman-token': '1b9f30b4-9d66-d59e-7e44-0a2f7f45c0f4'
//                }
//            });

//            $.ajax(settings).done(function (response) {
//            debugger
//                console.log(response);
//            });


});

        function ErrorFunction() {
            lbl.innerHTML = "No Data";

        }
</script>-->
<script type="text/javascript">
    $(document).ready(function () {

        $('#_testButton').click(function () {
            debugger;
            var file = document.getElementById('_testFile').files[0];
            var serverUrl = 'http://hsapirepo.azurewebsites.net/api/hs/salunkhe/moodkyahai';

            $.ajax({
                type: "POST",
                beforeSend: function (request) {
                    request.setRequestHeader("Content-Type", file.type);
                },
                url: serverUrl,
                data: file,
                processData: false,
                contentType: false,
                success: function (data) {
                    lbl.innerHTML = data.toString();
                },
                error: function (data) {
                    debugger;
                    var obj = jQuery.parseJSON(data);
                    alert(obj.error);
                }
            });
        });
    });
        </script>
</head>

<body>
<form action="#">

<input type=file name="_testFile" id="_testFile" />
<input type="button" id="_testButton" />

  <div id="popupdiv" style="Background-color:Aqua;">

</div>
<label id="lbl"></label>
</form>
</body>

</html>

Popular posts from this blog

Add barcode on pdf

using System; using System.IO; using System.Drawing; using ZXing; using iTextSharp.text; using iTextSharp.text.pdf; using System.Drawing; using System.Web.UI.WebControls; namespace PDFBarcode {     public partial class WebForm1 : System.Web.UI.Page     {         byte[] byteImage;         protected void Page_Load(object sender, EventArgs e)         {         }         protected void btnDownload_Click(object sender, EventArgs e)         {                       Random r = new Random();             string fileName = r.Next().ToString();             string filenameext = fileName + ".pdf";             GenerateBarcode(fileName);             string Sourcepath = Server.MapPath("~/SavedF...

Dynamic Menu in asp.net using Listview

 1.    public DataTable LoadMenu()         {             MenuBal MenuBal = new MenuBal();             DataSet ds = this.GetData(0);             PopulateMenu(ds);             return ds.Tables[2];         }     private DataSet GetData(int parentMenuId)         {             MenuBal objmenu = new MenuBal();             string Mode = "";             if (Session["Mode"] != null)             {                 Mode = Session["Mode"].ToString();             }             DataSet ds = objmenu.GetData(parentMenuId, Convert.ToInt32(SessionHelper.CurrentUserId), Mode, SessionHelper...