0

Java script

$('#senurl').click(function () {

    $.ajax({
        type: "POST",
        url: "/Admin/Coupon1/Reject",
        dataType: "json",
        data:  "id="[email protected]+"&url="+@url

    });
});

ReferenceError: Expired is not defined
[Break On This Error]
data: "id="+2925+"&url="+Expired

3
  • Provided code sample seems ok, error is somewhere else Commented Feb 6, 2013 at 11:44
  • I can't see when you use Expired variable. Is that your complete source code? Commented Feb 6, 2013 at 11:44
  • 3
    The problem should be obvious: @url seems to be replaced by Expired (by the server), which does not seem to be an existing variable. I assume you want to treat it as a string: +"&url=@url". Commented Feb 6, 2013 at 11:45

3 Answers 3

2

You probably want (but see also below):

$('#senurl').click(function () {

    $.ajax({
        type: "POST",
        url: "/Admin/Coupon1/Reject",
        dataType: "json",
        data:  "[email protected]&url=@url"

    });
});

...because you have to think about what the browser sees, and if @url gets replaced with Expired by the server, from the error you can tell that what the browser sees for your code is:

data: "id="+2925+"&url="+Expired // <=== What the browser sees with your current code

Even better, let jQuery handle any potential URI-encoding needed by passing it an object instead:

$('#senurl').click(function () {

    $.ajax({
        type: "POST",
        url: "/Admin/Coupon1/Reject",
        dataType: "json",
        data:  {id: @Model.id, url: "@url"}
    });
});

If you don't want to pass jQuery an object and let it handle the URI-encoding for you, then you'll want to handle it yourself:

data:  "[email protected]&url=" + encodeURIComponent("@url")
Sign up to request clarification or add additional context in comments.

Comments

0

$('#senurl').click(function () {

$.ajax({
    type: "POST",
    url: "/Admin/Coupon1/Reject",
    dataType: "json",
data: "{id:'" + @Model.id + "', 'url': " + @url + "}",  
   success: function (response) {
    alert( response.d); 
},
error: function (data) {
    alert(data);
},
failure: function (msg) {

}
});

});

Try this it is working fine. If you are using url routing then you might get some other error. so better get the respone output and check..

Comments

-1

I think its because @url variable is assigned data Expired without quotes.

2 Comments

I think its because @url variable is assigned data Expired without quotes.
Yes... so why don't you have it in your answer? :)

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.