3

I am doing this for the first time. i want a data of another HTML page using AJAX call and jQuery in HTML page. Below is mycode

this is my .js code

<script type="text/javascript">
$(document).ready(function()
{
    $('#submit').click(function(){
        var name =$('#name').val();
        var pass =$('#passsword').val();
        if(name=='' || pass==''){
            alert('first fill the details');
        }
        else {
            $.ajax({
                    method:'POST',
                    url:"login.html",
                    data:{name:name,
                    password:pass},
                    daatType:"HTML",
                    success:function(status) {
                            alert('success');
                            $('#div').html(status);
                        } 
                })

        }

    })
})

this is my Html code

<form>
   <label>Name:</label><input type="text" id="name"><br>
   <label>Password:</label><input type="text" id="password"><br>
   <button type="submit" id="submit" >Submit</button>
</form>
<h2 id="div"></h2>

please help

3
  • there might be a typo in your jQuery code: daatType instead if dataType I guess Commented May 17, 2017 at 10:02
  • What is the value of the status variable? You could take data to next page using a url parameter. For eg if the next page is www.abc.com/def.html, Then you can do www.abc.com/def.html#This is data. In the new html page you can get this value using javascript : var x = location.hash; Commented May 17, 2017 at 10:07
  • Please clear whether your data is short or long ? If it is short and not sensitive you can pass in URL like this. window.location.href = site_url + 'status/' + data; do it in your success function. Commented May 17, 2017 at 10:11

1 Answer 1

2

Change dataType:"HTML" to dataType:"json"

dataType:'json' // its mean server return type data

whereas

contentType:'json' // send data type to server should be json
Sign up to request clarification or add additional context in comments.

1 Comment

i did this change but it was not solving the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.