Click here to Skip to main content
15,909,591 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,

I wanted to pass some model data of my view through Ajax Call,

HTML
<script type="text/javascript">

    $(document).ready(function () {

        $("#requestChange").click(function () {
            var webUrl;
            var email=$('#x=>x.StoreProfileAssociation.BusinessEmail')
            webUrl = "UpdateChangeRequest"            
            $.ajax(
                {
                    type: 'POST',
                    data: { 'From': '', 'To': 'email', 'Subject': 'myMOL Change Request for #', 'Body': $('#changeRequest').val(), 'Priority': 'High' },
                    datatype: "json",
                    url: webUrl,
                    success: function (data) {
                        //var json = data;
                        //console.log(json);
                        //$('#_genericReport').html('');
                        //$('#_genericReport').html(data);

                    },
                    error: function (result) {
                        alert('Failed to load the result');
                    }
                })
        });
    });


</script>

Exception:<pre lang="C#">jquery-2.2.2.js:1468 Uncaught Error: Syntax error, unrecognized expression: #x=&gt;x.StoreProfileAssociation.BusinessEmail</pre>



basically i want to retrieve a model data (customerEmail) and pass it to my controller from view through ajax call

What I have tried:

var email=$('#x=>x.StoreProfileAssociation.BusinessEmail')
Posted
Updated 26-Apr-16 2:35am
Comments
Karthik_Mahalingam 26-Apr-16 7:44am    
mvc ?
F-ES Sitecore 26-Apr-16 7:51am    
Where does StoreProfileAssociation.BusinessEmail come from? Is that data on the model?
sahmed3 26-Apr-16 8:34am    
Yes,

1 solution

Thank you all, for your responses,

I have resolved

var from = '@Model.StoreProfileAssociation.BusinessEmail';
            var to = '@System.Configuration.ConfigurationManager.AppSettings["fromemailreminder"]';


JavaScript
$.ajax(
               {
                   type: 'POST',
                   data: { 'From': from, 'To': to, 'Subject': 'myMOL Change Request for #', 'Body': $('#changeRequest').val(), 'Priority': 'High' },
                   datatype: "json",
                   url: webUrl,
                   success: function (data) {
                       alert('Your request has been sent. Changes will be processed within the next 7-10 business days.')

                   },
                   error: function (result) {
                       alert('Failed to load the result');
                   }
               })
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900